@ctrl/ngx-emoji-mart 8.0.0 → 8.1.0

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.
@@ -1,6 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, EventEmitter, Component, ChangeDetectionStrategy, Input, Output, NgModule } from '@angular/core';
3
- import * as i2 from '@angular/common';
2
+ import { Injectable, EventEmitter, inject, NgZone, Component, ChangeDetectionStrategy, Input, Output, ViewChild, NgModule } from '@angular/core';
3
+ import { Subject, switchMap, fromEvent, EMPTY, takeUntil } from 'rxjs';
4
+ import * as i1 from '@angular/common';
4
5
  import { CommonModule } from '@angular/common';
5
6
 
6
7
  const categories = [
@@ -34033,8 +34034,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
34033
34034
  }], ctorParameters: function () { return []; } });
34034
34035
 
34035
34036
  class EmojiComponent {
34036
- constructor(emojiService) {
34037
- this.emojiService = emojiService;
34037
+ set button(button) {
34038
+ // Note: `runOutsideAngular` is used to trigger `addEventListener` outside of the Angular zone
34039
+ // too. See `setupMouseEnterListener`. The `switchMap` will subscribe to `fromEvent` considering
34040
+ // the context where the factory is called in.
34041
+ this.ngZone.runOutsideAngular(() => this.button$.next(button?.nativeElement));
34042
+ }
34043
+ constructor() {
34038
34044
  this.skin = 1;
34039
34045
  this.set = 'apple';
34040
34046
  this.sheetSize = 64;
@@ -34046,7 +34052,14 @@ class EmojiComponent {
34046
34052
  this.emoji = '';
34047
34053
  this.hideObsolete = false;
34048
34054
  this.emojiOver = new EventEmitter();
34055
+ /**
34056
+ * Note: `emojiLeave` and `emojiLeaveOutsideAngular` are dispatched on the same event, but for different
34057
+ * purposes. The `emojiLeaveOutsideAngular` would be set up in category component so we don't care
34058
+ * about zone context the callback is being called in. The `emojiLeave` is for backwards compatibility
34059
+ * if anyone is listening to this event explicitly in their code.
34060
+ */
34049
34061
  this.emojiLeave = new EventEmitter();
34062
+ this.emojiLeaveOutsideAngular = new EventEmitter();
34050
34063
  this.emojiClick = new EventEmitter();
34051
34064
  this.title = undefined;
34052
34065
  this.label = '';
@@ -34054,6 +34067,15 @@ class EmojiComponent {
34054
34067
  this.isVisible = true;
34055
34068
  // TODO: replace 4.0.3 w/ dynamic get verison from emoji-datasource in package.json
34056
34069
  this.backgroundImageFn = DEFAULT_BACKGROUNDFN;
34070
+ /**
34071
+ * The subject used to emit whenever view queries are run and `button` or `span` is set/removed.
34072
+ * We use subject to keep the reactive behavior so we don't have to add and remove event listeners manually.
34073
+ */
34074
+ this.button$ = new Subject();
34075
+ this.destroy$ = new Subject();
34076
+ this.ngZone = inject(NgZone);
34077
+ this.emojiService = inject(EmojiService);
34078
+ this.setupMouseLeaveListener();
34057
34079
  }
34058
34080
  ngOnChanges() {
34059
34081
  if (!this.emoji) {
@@ -34126,6 +34148,9 @@ class EmojiComponent {
34126
34148
  }
34127
34149
  return (this.isVisible = true);
34128
34150
  }
34151
+ ngOnDestroy() {
34152
+ this.destroy$.next();
34153
+ }
34129
34154
  getData() {
34130
34155
  return this.emojiService.getData(this.emoji, this.skin, this.set);
34131
34156
  }
@@ -34140,92 +34165,110 @@ class EmojiComponent {
34140
34165
  const emoji = this.getSanitizedData();
34141
34166
  this.emojiOver.emit({ emoji, $event });
34142
34167
  }
34143
- handleLeave($event) {
34144
- const emoji = this.getSanitizedData();
34145
- this.emojiLeave.emit({ emoji, $event });
34168
+ setupMouseLeaveListener() {
34169
+ this.button$
34170
+ .pipe(
34171
+ // Note: `EMPTY` is used to remove event listener once the DOM node is removed.
34172
+ switchMap(button => (button ? fromEvent(button, 'mouseleave') : EMPTY)), takeUntil(this.destroy$))
34173
+ .subscribe($event => {
34174
+ const emoji = this.getSanitizedData();
34175
+ this.emojiLeaveOutsideAngular.emit({ emoji, $event });
34176
+ // Note: this is done for backwards compatibility. We run change detection if developers
34177
+ // are listening to `emojiLeave` in their code. For instance:
34178
+ // `<ngx-emoji (emojiLeave)="..."></ngx-emoji>`.
34179
+ if (this.emojiLeave.observed) {
34180
+ this.ngZone.run(() => this.emojiLeave.emit({ emoji, $event }));
34181
+ }
34182
+ });
34146
34183
  }
34147
34184
  }
34148
- EmojiComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: EmojiComponent, deps: [{ token: EmojiService }], target: i0.ɵɵFactoryTarget.Component });
34149
- EmojiComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.8", type: EmojiComponent, selector: "ngx-emoji", inputs: { skin: "skin", set: "set", sheetSize: "sheetSize", isNative: "isNative", forceSize: "forceSize", tooltip: "tooltip", size: "size", emoji: "emoji", fallback: "fallback", hideObsolete: "hideObsolete", sheetRows: "sheetRows", sheetColumns: "sheetColumns", useButton: "useButton", backgroundImageFn: "backgroundImageFn", imageUrlFn: "imageUrlFn" }, outputs: { emojiOver: "emojiOver", emojiLeave: "emojiLeave", emojiClick: "emojiClick" }, usesOnChanges: true, ngImport: i0, template: `
34150
- <button
34151
- *ngIf="useButton && isVisible"
34152
- type="button"
34153
- (click)="handleClick($event)"
34154
- (mouseenter)="handleOver($event)"
34155
- (mouseleave)="handleLeave($event)"
34156
- [attr.title]="title"
34157
- [attr.aria-label]="label"
34158
- class="emoji-mart-emoji"
34159
- [class.emoji-mart-emoji-native]="isNative"
34160
- [class.emoji-mart-emoji-custom]="custom"
34161
- >
34162
- <span [ngStyle]="style">
34163
- <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34164
- <ng-content></ng-content>
34165
- </span>
34166
- </button>
34185
+ EmojiComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: EmojiComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
34186
+ EmojiComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.8", type: EmojiComponent, selector: "ngx-emoji", inputs: { skin: "skin", set: "set", sheetSize: "sheetSize", isNative: "isNative", forceSize: "forceSize", tooltip: "tooltip", size: "size", emoji: "emoji", fallback: "fallback", hideObsolete: "hideObsolete", sheetRows: "sheetRows", sheetColumns: "sheetColumns", useButton: "useButton", backgroundImageFn: "backgroundImageFn", imageUrlFn: "imageUrlFn" }, outputs: { emojiOver: "emojiOver", emojiLeave: "emojiLeave", emojiLeaveOutsideAngular: "emojiLeaveOutsideAngular", emojiClick: "emojiClick" }, viewQueries: [{ propertyName: "button", first: true, predicate: ["button"], descendants: true }], usesOnChanges: true, ngImport: i0, template: `
34187
+ <ng-template [ngIf]="isVisible">
34188
+ <button
34189
+ *ngIf="useButton; else spanTpl"
34190
+ #button
34191
+ type="button"
34192
+ (click)="handleClick($event)"
34193
+ (mouseenter)="handleOver($event)"
34194
+ [attr.title]="title"
34195
+ [attr.aria-label]="label"
34196
+ class="emoji-mart-emoji"
34197
+ [class.emoji-mart-emoji-native]="isNative"
34198
+ [class.emoji-mart-emoji-custom]="custom"
34199
+ >
34200
+ <span [ngStyle]="style">
34201
+ <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34202
+ <ng-content></ng-content>
34203
+ </span>
34204
+ </button>
34205
+ </ng-template>
34167
34206
 
34168
- <span
34169
- *ngIf="!useButton && isVisible"
34170
- (click)="handleClick($event)"
34171
- (mouseenter)="handleOver($event)"
34172
- (mouseleave)="handleLeave($event)"
34173
- [attr.title]="title"
34174
- [attr.aria-label]="label"
34175
- class="emoji-mart-emoji"
34176
- [class.emoji-mart-emoji-native]="isNative"
34177
- [class.emoji-mart-emoji-custom]="custom"
34178
- >
34179
- <span [ngStyle]="style">
34180
- <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34181
- <ng-content></ng-content>
34207
+ <ng-template #spanTpl>
34208
+ <span
34209
+ #button
34210
+ (click)="handleClick($event)"
34211
+ (mouseenter)="handleOver($event)"
34212
+ [attr.title]="title"
34213
+ [attr.aria-label]="label"
34214
+ class="emoji-mart-emoji"
34215
+ [class.emoji-mart-emoji-native]="isNative"
34216
+ [class.emoji-mart-emoji-custom]="custom"
34217
+ >
34218
+ <span [ngStyle]="style">
34219
+ <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34220
+ <ng-content></ng-content>
34221
+ </span>
34182
34222
  </span>
34183
- </span>
34184
- `, isInline: true, dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
34223
+ </ng-template>
34224
+ `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
34185
34225
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImport: i0, type: EmojiComponent, decorators: [{
34186
34226
  type: Component,
34187
34227
  args: [{
34188
34228
  selector: 'ngx-emoji',
34189
34229
  template: `
34190
- <button
34191
- *ngIf="useButton && isVisible"
34192
- type="button"
34193
- (click)="handleClick($event)"
34194
- (mouseenter)="handleOver($event)"
34195
- (mouseleave)="handleLeave($event)"
34196
- [attr.title]="title"
34197
- [attr.aria-label]="label"
34198
- class="emoji-mart-emoji"
34199
- [class.emoji-mart-emoji-native]="isNative"
34200
- [class.emoji-mart-emoji-custom]="custom"
34201
- >
34202
- <span [ngStyle]="style">
34203
- <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34204
- <ng-content></ng-content>
34205
- </span>
34206
- </button>
34230
+ <ng-template [ngIf]="isVisible">
34231
+ <button
34232
+ *ngIf="useButton; else spanTpl"
34233
+ #button
34234
+ type="button"
34235
+ (click)="handleClick($event)"
34236
+ (mouseenter)="handleOver($event)"
34237
+ [attr.title]="title"
34238
+ [attr.aria-label]="label"
34239
+ class="emoji-mart-emoji"
34240
+ [class.emoji-mart-emoji-native]="isNative"
34241
+ [class.emoji-mart-emoji-custom]="custom"
34242
+ >
34243
+ <span [ngStyle]="style">
34244
+ <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34245
+ <ng-content></ng-content>
34246
+ </span>
34247
+ </button>
34248
+ </ng-template>
34207
34249
 
34208
- <span
34209
- *ngIf="!useButton && isVisible"
34210
- (click)="handleClick($event)"
34211
- (mouseenter)="handleOver($event)"
34212
- (mouseleave)="handleLeave($event)"
34213
- [attr.title]="title"
34214
- [attr.aria-label]="label"
34215
- class="emoji-mart-emoji"
34216
- [class.emoji-mart-emoji-native]="isNative"
34217
- [class.emoji-mart-emoji-custom]="custom"
34218
- >
34219
- <span [ngStyle]="style">
34220
- <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34221
- <ng-content></ng-content>
34250
+ <ng-template #spanTpl>
34251
+ <span
34252
+ #button
34253
+ (click)="handleClick($event)"
34254
+ (mouseenter)="handleOver($event)"
34255
+ [attr.title]="title"
34256
+ [attr.aria-label]="label"
34257
+ class="emoji-mart-emoji"
34258
+ [class.emoji-mart-emoji-native]="isNative"
34259
+ [class.emoji-mart-emoji-custom]="custom"
34260
+ >
34261
+ <span [ngStyle]="style">
34262
+ <ng-template [ngIf]="isNative">{{ unified }}</ng-template>
34263
+ <ng-content></ng-content>
34264
+ </span>
34222
34265
  </span>
34223
- </span>
34266
+ </ng-template>
34224
34267
  `,
34225
34268
  changeDetection: ChangeDetectionStrategy.OnPush,
34226
34269
  preserveWhitespaces: false,
34227
34270
  }]
34228
- }], ctorParameters: function () { return [{ type: EmojiService }]; }, propDecorators: { skin: [{
34271
+ }], ctorParameters: function () { return []; }, propDecorators: { skin: [{
34229
34272
  type: Input
34230
34273
  }], set: [{
34231
34274
  type: Input
@@ -34255,12 +34298,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.8", ngImpor
34255
34298
  type: Output
34256
34299
  }], emojiLeave: [{
34257
34300
  type: Output
34301
+ }], emojiLeaveOutsideAngular: [{
34302
+ type: Output
34258
34303
  }], emojiClick: [{
34259
34304
  type: Output
34260
34305
  }], backgroundImageFn: [{
34261
34306
  type: Input
34262
34307
  }], imageUrlFn: [{
34263
34308
  type: Input
34309
+ }], button: [{
34310
+ type: ViewChild,
34311
+ args: ['button', { static: false }]
34264
34312
  }] } });
34265
34313
 
34266
34314
  class EmojiModule {