@mediafly/js-ui 52.0.1 → 53.0.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.
@@ -14,8 +14,17 @@ export interface FeedbackOptions {
14
14
  copyLinkText?: string
15
15
  copySuccessMessage?: string
16
16
  manualClose?: boolean
17
- type?: FeedbackType
18
17
  trustAsHtml?: boolean
18
+ type?: FeedbackType
19
+ }
20
+
21
+ export interface FeedbackAlert {
22
+ clipboardContents?: string
23
+ copyLinkText?: string
24
+ copySuccessMessage?: string
25
+ message?: string
26
+ trustAsHtml: boolean
27
+ type: FeedbackType
19
28
  }
20
29
 
21
30
  @Component({
@@ -23,13 +32,12 @@ export interface FeedbackOptions {
23
32
  template: require('./feedback.component.html'),
24
33
  })
25
34
  export default class FeedbackManager implements IComponentController {
26
- protected alerts: object[] = []
35
+ protected alerts: FeedbackAlert[] = []
27
36
  private timer: ng.IPromise<any> | undefined
28
37
 
29
38
  constructor(
30
39
  @Inject('$interval') private $interval: ng.IIntervalService,
31
40
  @Inject('$rootScope') private $rootScope: ng.IRootScopeService,
32
- @Inject('$sanitize') private $sanitize: ng.sanitize.ISanitizeService,
33
41
  @Inject('$sce') private $sce: ng.ISCEService,
34
42
  @Inject('$timeout') private $timeout: ng.ITimeoutService,
35
43
  @Inject('clipboardService') private clipboardService: ClipboardService,
@@ -42,24 +50,15 @@ export default class FeedbackManager implements IComponentController {
42
50
 
43
51
  this.$rootScope.$on('showFeedback', (event, args: FeedbackOptions & {alertMessage: string}) => {
44
52
 
45
- args.alertMessage = args.trustAsHtml ? args.alertMessage : this.$sanitize(args.alertMessage)
46
-
47
53
  if (args.autoCopyContents && args.clipboardContents) {
48
54
  throw new Error('The clipboardContents and autoCopyContents options are mutually exclusive.')
49
55
  }
50
56
 
51
- if (args.clipboardContents && args.copyLinkText) {
52
- args.alertMessage += `<br/><a class="o-link" data-clipboard-text="${this.$sanitize(args.clipboardContents)}" data-clipboard-success="${this.$sanitize(args.copySuccessMessage || '')}">
53
- ${this.$sanitize(args.copyLinkText)}
54
- </a>`
55
- }
56
-
57
57
  if (args.autoCopyContents) {
58
58
  this.clipboardService.writeToClipboard(args.autoCopyContents, args.copySuccessMessage)
59
59
  return
60
60
  }
61
61
 
62
- this.removeTimer(this.timer)
63
62
  this.addAlert(args.alertMessage, args)
64
63
  })
65
64
  }
@@ -68,10 +67,10 @@ export default class FeedbackManager implements IComponentController {
68
67
  window.removeEventListener('click', this.handleFeedbackClick)
69
68
  }
70
69
 
71
- protected closeAlert(index: number) {
70
+ protected closeAlert() {
72
71
 
73
72
  this.removeTimer(this.timer)
74
- this.alerts.splice(index, 1)
73
+ this.alerts = []
75
74
  }
76
75
 
77
76
  private handleFeedbackClick = (event: MouseEvent) => {
@@ -89,15 +88,28 @@ export default class FeedbackManager implements IComponentController {
89
88
 
90
89
  private addAlert(message: string, options: FeedbackOptions) {
91
90
 
92
- this.alerts = [{
93
- msg: this.$sce.trustAsHtml(message),
94
- type: options.type || 'warning'
95
- }]
91
+ this.removeTimer(this.timer)
92
+
93
+ const trustAsHtml = !!options.trustAsHtml
94
+ const alert: FeedbackAlert = {
95
+ clipboardContents: options.clipboardContents || undefined,
96
+ copyLinkText: options.copyLinkText,
97
+ copySuccessMessage: options.copySuccessMessage,
98
+ trustAsHtml,
99
+ type: options.type || 'warning',
100
+ }
101
+
102
+ if (trustAsHtml) {
103
+ alert.message = this.$sce.trustAsHtml(message) as string
104
+ } else {
105
+ alert.message = message
106
+ }
107
+
108
+ this.alerts = [alert]
96
109
 
97
110
  if (!options.manualClose) {
98
111
  this.timer = this.$interval(() => {
99
- this.removeTimer(this.timer)
100
- this.closeAlert(this.alerts.length - 1)
112
+ this.closeAlert()
101
113
  }, 5000, 1)
102
114
  }
103
115
  }
@@ -69,7 +69,9 @@
69
69
  }
70
70
  }
71
71
 
72
- .c-feedback__message {
72
+ .c-feedback__message,
73
+ .c-feedback__copy-link-break,
74
+ .c-feedback__copy-link {
73
75
  font-size: @font-size-base;
74
76
  }
75
77