@mediafly/js-ui 47.2.0 → 47.3.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +2 -14
  2. package/lib/auto-complete/auto-complete.component.html +2 -1
  3. package/lib/font-selector/font-selector.d.ts +37 -8
  4. package/lib/font-selector/font-selector.html +58 -13
  5. package/lib/font-selector/font-selector.js +174 -17
  6. package/lib/font-selector/font-selector.js.map +1 -1
  7. package/lib/font-selector/google-webfonts-api.service.d.ts +1 -1
  8. package/lib/font-selector/google-webfonts-api.service.js +10 -2
  9. package/lib/font-selector/google-webfonts-api.service.js.map +1 -1
  10. package/lib/font-selector/webfont-loader.service.d.ts +1 -2
  11. package/lib/font-selector/webfont-loader.service.js +2 -2
  12. package/lib/font-selector/webfont-loader.service.js.map +1 -1
  13. package/lib/jsui.module.css +13 -2
  14. package/lib/rich-text/index.d.ts +0 -1
  15. package/lib/rich-text/index.js +0 -1
  16. package/lib/rich-text/index.js.map +1 -1
  17. package/lib/rich-text/rich-text.component.d.ts +2 -2
  18. package/lib/rich-text/rich-text.component.html +6 -14
  19. package/lib/rich-text/rich-text.component.js +6 -5
  20. package/lib/rich-text/rich-text.component.js.map +1 -1
  21. package/lib/styles.css +25 -16
  22. package/lib/tsconfig.deploy.tsbuildinfo +17 -29
  23. package/package.json +2 -2
  24. package/src/components/auto-complete/auto-complete.component.html +2 -1
  25. package/src/components/auto-complete/auto-complete.component.less +2 -1
  26. package/src/components/font-selector/font-selector.html +58 -13
  27. package/src/components/font-selector/font-selector.less +100 -0
  28. package/src/components/font-selector/font-selector.ts +191 -17
  29. package/src/components/font-selector/google-webfonts-api.backend.ts +1 -1
  30. package/src/components/font-selector/google-webfonts-api.service.ts +10 -2
  31. package/src/components/font-selector/webfont-loader.service.ts +2 -2
  32. package/src/components/index.less +1 -1
  33. package/src/components/less/objects/buttons.less +8 -0
  34. package/src/components/less/objects/buttons.module.css +11 -0
  35. package/src/components/less/variables/colors.less +2 -2
  36. package/src/components/less/variables.module.css +2 -2
  37. package/src/components/rich-text/index.ts +0 -1
  38. package/src/components/rich-text/rich-text.component.html +6 -14
  39. package/src/components/rich-text/rich-text.component.less +5 -1
  40. package/src/components/rich-text/rich-text.component.ts +7 -5
  41. package/tsconfig.tsbuildinfo +46 -63
  42. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  43. package/.idea/jsLinters/jshint.xml +0 -16
  44. package/.idea/mediafly-js-ui.iml +0 -12
  45. package/.idea/modules.xml +0 -8
  46. package/.idea/vcs.xml +0 -6
  47. package/lib/rich-text/rich-text-toolbar-container.component.d.ts +0 -16
  48. package/lib/rich-text/rich-text-toolbar-container.component.html +0 -12
  49. package/lib/rich-text/rich-text-toolbar-container.component.js +0 -75
  50. package/lib/rich-text/rich-text-toolbar-container.component.js.map +0 -1
  51. package/src/components/rich-text/rich-text-toolbar-container.component.html +0 -12
  52. package/src/components/rich-text/rich-text-toolbar-container.component.ts +0 -66
  53. package/src/components/rich-text/rich-text-toolbar-container.less +0 -21
@@ -1,9 +1,8 @@
1
1
  import { Component, Inject, Input, Output } from '../decorators'
2
2
  import GoogleWebfontsApiService from './google-webfonts-api.service'
3
- import { AutoCompleteMatchObject } from '../auto-complete/auto-complete-match-renderer.component'
4
3
  import WebfontLoaderService from './webfont-loader.service'
5
4
  import { TranslateFactory } from '../translate/translate-factory'
6
-
5
+ import _ from 'lodash'
7
6
 
8
7
  export interface FontFamilyStyle {
9
8
  'font-family': string
@@ -16,48 +15,223 @@ export interface FontFamilyStyle {
16
15
 
17
16
  export default class FontSelectorController implements ng.IComponentController {
18
17
 
19
- @Input() isDisabled?: boolean
20
- @Input() isRequired?: boolean
21
- @Output() onFontSelect!: (param: { font: google.fonts.WebfontFamily }) => void
22
-
18
+ @Input('<') inputId!: string
19
+ @Input('<') isDisabled?: boolean
20
+ @Input('<') isRequired?: boolean
21
+ @Input('=?') fontFamily?: string
22
+
23
+ @Output('&?') onFontSelect?: (param: { fontFamily: string }) => void
24
+
25
+ protected delay: number = 500
26
+ protected googleFonts: string[]
27
+ protected inputValue?: string
28
+ protected interactionMode: 'mouse' | 'keyboard' = 'mouse'
29
+ protected isDropdownVisible: boolean
30
+ protected isFetching: boolean
31
+ protected kbSelectedIndex = -1
32
+ protected keyEventElement: HTMLInputElement | null = null
33
+ protected loadingFonts: boolean = true
23
34
  protected placeholderText!: string
35
+ protected matches: string[] = []
36
+ protected minLength: number = 2
37
+ protected requiredText: string
38
+
39
+ private debouncedFetchAndSetMatches = _.debounce(() => this.fetchAndSetMatches(), this.delay)
40
+ private inputElement: HTMLElement
41
+ private observer: MutationObserver
24
42
 
25
43
  constructor (
44
+ @Inject('$document') private $document: ng.IDocumentService,
45
+ @Inject('$element') private $element: ng.IAugmentedJQuery,
46
+ @Inject('$timeout') private $timeout: ng.ITimeoutService,
47
+ @Inject('$q') private $q: ng.IQService,
26
48
  @Inject('googleWebfontsApiService') private googleWebfontsApiService: GoogleWebfontsApiService,
27
49
  @Inject('translateFactory') private translateFactory: TranslateFactory,
28
50
  @Inject('webfontLoaderService') private webfontLoaderService: WebfontLoaderService,
29
51
  ) {}
30
52
 
31
- protected googleFonts: google.fonts.WebfontFamily[]
53
+ $onDestroy() {
54
+ if (this.keyEventElement) {
55
+ this.keyEventElement.removeEventListener('input', this.debouncedFetchAndSetMatches)
56
+ this.keyEventElement.removeEventListener('keydown', this.onKeyDown)
57
+ }
58
+
59
+ const body = (this.$document[0] as Document).body
60
+ body.removeEventListener('click', this.onClickElsewhere)
61
+
62
+ this.observer.disconnect()
63
+ }
32
64
 
33
65
  $onInit() {
66
+ if (!this.inputId) { throw new Error(`You must provide a string to key-event-element-id on the AutoCompleteMatchRenderer.`) }
34
67
  // set label text
35
68
  this.placeholderText = this.translateFactory.instant('JSUI.SEARCH_FONTS')
36
69
 
70
+ this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
71
+
37
72
  // init list of google fonts
38
73
  this.googleWebfontsApiService.getFontList()
39
- .then(fontList => { this.googleFonts = fontList })
74
+ .then(fontList => {
75
+ this.googleFonts = fontList.map(f => f.family)
76
+ this.loadingFonts = false
77
+ })
78
+
79
+ const body = (this.$document[0] as Document).body
80
+ body.addEventListener('click', this.onClickElsewhere)
81
+
82
+ // Set up an observer that will find the input element and attach events when it is present.
83
+ this.observer = new MutationObserver(() => {
84
+ // expect the tag-input component to be defined in a div with the id autocomplete-tag-lookup
85
+ // this allows us to more reliably find the input to listen to when there are multiple instances of this combination
86
+ this.inputElement = this.$element.parent().find(`#${this.inputId}`)[0]
87
+ if (this.inputElement) {
88
+ this.keyEventElement = this.inputElement as HTMLInputElement
89
+ this.keyEventElement.addEventListener('input', this.debouncedFetchAndSetMatches)
90
+ this.keyEventElement.addEventListener('keydown', this.onKeyDown)
91
+ this.observer.disconnect()
92
+ }
93
+ })
94
+
95
+ this.observer.observe(body, { attributes: true, childList: true, characterData: false, subtree: true })
96
+ }
97
+
98
+ protected clearInput($event): void {
99
+ this.inputValue = ''
100
+ $event.stopPropagation()
40
101
  }
41
102
 
42
- protected onFontLookup(value: string): AutoCompleteMatchObject<google.fonts.WebfontFamily>[] {
103
+ protected clickSelect($event): void {
104
+ if (this.isDisabled) { return }
105
+ this.isDropdownVisible = !this.isDropdownVisible
106
+ if (this.isDropdownVisible) {
107
+ this.$timeout(() => {
108
+ this.inputElement.focus()
109
+ }, 250)
110
+ }
111
+ $event.stopPropagation()
112
+ }
113
+
114
+ // When the user mouses over the dropdown, we should remove any keyboard
115
+ // highlighting, since the mouse hover provides it too.
116
+ dropdownWasMousedOver() {
117
+ this.interactionMode = 'mouse'
118
+ this.kbSelectedIndex = -1
119
+ }
120
+
121
+ protected inputClick($event): void{
122
+ $event.stopPropagation()
123
+ }
124
+
125
+ protected inputValueWasChanged() {
126
+ this.debouncedFetchAndSetMatches()
127
+ }
128
+
129
+ protected matchWasSelected(match: string) {
130
+ this.matches = []
131
+ this.kbSelectedIndex = -1
132
+ this.inputValue = ''
133
+ this.fontFamily = match
134
+ this.isDropdownVisible = false
135
+ if (this.onFontSelect) {
136
+ this.onFontSelect({fontFamily: this.fontFamily})
137
+ }
138
+ }
139
+
140
+ protected onFontLookup(value: string): ng.IPromise<string[]> {
141
+
142
+ value = value.toLocaleLowerCase()
43
143
 
144
+ // const fonts: google.fonts.WebfontFamily[] = []
44
145
  const fonts = this.googleFonts.filter(font => {
45
- return font.family.toLowerCase().includes(value.toLowerCase())
146
+ return font.toLowerCase().includes(value)
46
147
  })
47
148
 
48
149
  // load this set with the api service
49
150
  this.webfontLoaderService.loadFonts(fonts)
50
151
 
152
+ return this.$q.resolve(fonts)
153
+ }
154
+
155
+ private fetchAndSetMatches(): void {
156
+
157
+ this.isFetching = true
51
158
 
52
- return fonts.map(font => ({
53
- cssStyle: { 'font-family': font.family } as FontFamilyStyle,
54
- displayValue: font.family,
55
- value: font
56
- }))
159
+ const input = this.inputValue || (this.keyEventElement ? this.keyEventElement.value : '')
57
160
 
161
+ if (input.length < this.minLength) {
162
+ this.$timeout(() => {
163
+ this.matches = []
164
+ })
165
+ return
166
+ }
167
+
168
+ this.isFetching = true
169
+
170
+ // Wrap the entire fetch in a timeout so that fetching callbacks will
171
+ // be called correctly while the async part happens.
172
+ this.$timeout(() => {
173
+ this.$q.when(this.onFontLookup(input))
174
+ .then(matches => {
175
+ this.matches = matches
176
+ this.isFetching = false
177
+ })
178
+ })
58
179
  }
59
180
 
60
- protected onSelect(font: google.fonts.WebfontFamily) {
61
- this.onFontSelect({ font })
181
+ private onClickElsewhere = ($event: MouseEvent) => {
182
+
183
+ this.$timeout(() => {
184
+ this.isDropdownVisible = false
185
+ })
186
+ }
187
+
188
+ private onKeyDown = ($event: KeyboardEvent) => this.$timeout(() => {
189
+
190
+ this.interactionMode = 'keyboard'
191
+
192
+ // Enter with no selection: let the $event through
193
+ if ($event.key === 'Enter' && this.kbSelectedIndex === -1) { return }
194
+
195
+ // If the dropdown is closed, all we can do is arrow down to open the thing
196
+ if (this.matches.length === 0 && $event.key !== 'ArrowDown') { return }
197
+
198
+ // Escape: close the dropdown
199
+ if ($event.key === 'Escape') { this.matches = [] }
200
+
201
+ // Arrow down with dropdown closed: fetch matches
202
+ if ($event.key === 'ArrowDown' && this.matches.length === 0) {
203
+ this.fetchAndSetMatches()
204
+ }
205
+
206
+ // Arrow keys with dropdown open: move the selection highlight
207
+ if ($event.key === 'ArrowDown' && this.matches.length > 0) {
208
+ const idx = Math.min(this.kbSelectedIndex + 1, this.matches.length - 1)
209
+ this.kbSelectedIndex = idx
210
+ this.scrollToMatch(idx)
211
+ }
212
+
213
+ if ($event.key === 'ArrowUp') {
214
+ const idx = Math.max(this.kbSelectedIndex - 1, 0)
215
+ this.kbSelectedIndex = idx
216
+ this.scrollToMatch(idx)
217
+ }
218
+
219
+ // Enter with a selection: set the selection to the currently highlighted match
220
+ if ($event.key === 'Enter' && this.kbSelectedIndex > -1) {
221
+ const match = this.matches[this.kbSelectedIndex]
222
+ this.matchWasSelected(match)
223
+ $event.preventDefault()
224
+ }
225
+
226
+ $event.stopPropagation()
227
+ })
228
+
229
+ private scrollToMatch(index: number) {
230
+
231
+ const row = this.$element.find('.c-font-selector__match-row')[index] as HTMLDivElement
232
+ if (row) {
233
+ row.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
234
+ }
62
235
  }
236
+
63
237
  }
@@ -3,6 +3,6 @@ import angular from 'angular'
3
3
  angular.module('app').run((
4
4
  $httpBackend: ng.IHttpBackendService
5
5
  ) => {
6
- $httpBackend.whenGET('https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyB-3EKXiPv1rjJ0Ab3u4s9iUaTqHXMLVOI').passThrough()
6
+ $httpBackend.whenGET(/^https:\/\/www.googleapis.com\/webfonts\/v1\/webfonts\?key=AIzaSyB-3EKXiPv1rjJ0Ab3u4s9iUaTqHXMLVOI(.*)?/).passThrough()
7
7
  })
8
8
 
@@ -10,8 +10,16 @@ export default class GoogleWebfontsApiService {
10
10
  ) { }
11
11
 
12
12
 
13
- getFontList(): ng.IPromise<google.fonts.WebfontFamily[]> {
14
- return this.$http.get<google.fonts.WebfontList>('https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyB-3EKXiPv1rjJ0Ab3u4s9iUaTqHXMLVOI')
13
+ getFontList(sort?: string): ng.IPromise<google.fonts.WebfontFamily[]> {
14
+ const call = 'https://www.googleapis.com/webfonts/v1/webfonts'
15
+
16
+ if (!sort) { sort = 'alpha' }
17
+
18
+ const params = {
19
+ key: 'AIzaSyB-3EKXiPv1rjJ0Ab3u4s9iUaTqHXMLVOI',
20
+ sort,
21
+ }
22
+ return this.$http.get<google.fonts.WebfontList>(call, { params })
15
23
  .then((response) => {
16
24
  return this.apiSuccessHandler.response(response).items
17
25
  })
@@ -5,9 +5,9 @@ import WebFont from 'webfontloader'
5
5
  export default class WebfontLoaderService {
6
6
 
7
7
 
8
- loadFonts(fontList: google.fonts.WebfontFamily[]): void {
8
+ loadFonts(families: string[]): void {
9
9
 
10
- const families = fontList.map(f => f.family)
10
+ // const families = fontList.map(f => f.family)
11
11
  let hasFonts = true
12
12
 
13
13
  try {
@@ -9,6 +9,7 @@
9
9
  @import './dropdown/dropdown';
10
10
  @import './feedback/feedback';
11
11
  @import './first-time-motivator/first-time-motivator';
12
+ @import './font-selector/font-selector';
12
13
  @import './footer/footer';
13
14
  @import './hierarchy/hierarchy';
14
15
  @import './hover-tooltip/hover-tooltip';
@@ -24,7 +25,6 @@
24
25
  @import './paging/paging';
25
26
  @import './progress-bar/progress-bar';
26
27
  @import './progress-circle/progress-circle';
27
- @import './rich-text/rich-text-toolbar-container.less';
28
28
  @import './rich-text/rich-text.component.less';
29
29
  @import './site-header/site-header';
30
30
  @import './slides/slides';
@@ -182,12 +182,20 @@
182
182
  // Small button
183
183
  // -------------------------------------------------
184
184
  &.o-button--small {
185
+ background: #fff;
186
+ border: 1px solid @color-gray-x-light;
185
187
  border-radius: 16px;
186
188
  font-size: 13px;
187
189
  font-weight: @font-weight-regular;
188
190
  line-height: 1;
189
191
  padding: 6px 12px;
190
192
  white-space: nowrap;
193
+
194
+ @media (hover) {
195
+ &:hover {
196
+ .hover-button();
197
+ }
198
+ }
191
199
  }
192
200
 
193
201
  // Fix outline border-radius for smaller buttons
@@ -96,12 +96,23 @@
96
96
  }
97
97
 
98
98
  .button.isSmall {
99
+ background: #fff;
100
+ border: 1px solid var(--color-gray-x-light);
99
101
  border-radius: 16px;
100
102
  font-size: 13px;
101
103
  font-weight: var(--font-weight-regular);
102
104
  height: auto; /* Match the non-module large button height instead of using fixed height of flex button */
103
105
  line-height: 1;
104
106
  padding: 6px 12px;
107
+
108
+ /* We set an explicit background on this button so we need more specificity on the hover style: */
109
+ @media (hover: hover) {
110
+ &:hover {
111
+ background-color: var(--color-button-default-hover-background);
112
+ border-color: var(--color-button-default-hover-border);
113
+ color: var(--color-button-default-text);
114
+ }
115
+ }
105
116
  }
106
117
 
107
118
  .button.isRoundRect {
@@ -29,8 +29,8 @@
29
29
  // ----------------------------------------------
30
30
  @color-success-light: #d8f2e6;
31
31
  @color-success: #008c48;
32
- @color-danger-light: #f7dfe4;
33
- @color-danger: #d90d36;
32
+ @color-danger-light: #f9ebee;
33
+ @color-danger: #89142e;
34
34
  @color-warning-light: #f9e4de;
35
35
  @color-warning: #de6a44;
36
36
  @color-info-light: #d8edf5;
@@ -32,8 +32,8 @@
32
32
  /* UI colors */
33
33
  --color-success-light: #d8f2e6;
34
34
  --color-success: #008c48;
35
- --color-danger-light: #f7dfe4;
36
- --color-danger: #d90d36;
35
+ --color-danger-light: #f9ebee;
36
+ --color-danger: #89142e;
37
37
  --color-warning-light: #f9e4de;
38
38
  --color-warning: #de6a44;
39
39
  --color-info-light: #d8edf5;
@@ -1,2 +1 @@
1
1
  import './rich-text.component'
2
- import './rich-text-toolbar-container.component'
@@ -1,19 +1,11 @@
1
1
  <div id="toolbar" class="c-rich-text">
2
2
 
3
- <span ng-if="$ctrl.allowFontSelection" class="ql-formats">
4
- <mfly:rich-text-toolbar-container>
5
- <mfly:toolbar-icon>
6
- <span ng-style="$ctrl.fontStyle">{{ $ctrl.selectedFont }}</span>
7
- <span class="c-rich-text-sort fas fa-sort"></span>
8
- </mfly:toolbar-icon>
9
- <mfly:toolbar-container>
10
- <mfly:font-selector
11
- label-text="{{ $ctrl.fontLabelText }}"
12
- on-font-select="$ctrl.fontSelected(font)">
13
- </mfly:font-selector>
14
- </mfly:toolbar-container>
15
- </mfly:rich-text-toolbar-container>
16
-
3
+ <span ng-if="$ctrl.allowFontSelection" class="ql-formats c-rich-text-font-container">
4
+ <mfly:font-selector
5
+ input-id="$ctrl.fontSelectorId"
6
+ font-family="$ctrl.selectedFont"
7
+ on-font-select="$ctrl.fontSelected(fontFamily)">
8
+ </mfly:font-selector>
17
9
  </span>
18
10
 
19
11
  <span class="ql-formats">
@@ -34,7 +34,7 @@ rich-text {
34
34
  }
35
35
 
36
36
  // override validation coloring
37
- .c-auto-complete__input {
37
+ .c-font-selector__dropdown__input {
38
38
  .c-rich-text & {
39
39
  border-color: #bbb !important; /* stylelint-disable-line declaration-no-important */
40
40
  }
@@ -45,6 +45,10 @@ rich-text {
45
45
  padding-left: 8px;
46
46
  }
47
47
 
48
+ .c-rich-text-font-container {
49
+ min-width: 140px;
50
+ }
51
+
48
52
  // Color class overrides
49
53
  .ql-color-\#e60000 { color: #e60000; }
50
54
  .ql-color-\#ff9900 { color: #f90; }
@@ -14,6 +14,7 @@ export default class RichTextComponentController implements ng.IComponentControl
14
14
  protected allowColorSelection?: boolean
15
15
  protected allowFontSelection?: boolean
16
16
  protected fontStyle?: FontFamilyStyle
17
+ protected fontSelectorId: string
17
18
  protected isRequired: boolean
18
19
  protected requiredText: string
19
20
  protected selectedColor: string
@@ -55,6 +56,7 @@ export default class RichTextComponentController implements ng.IComponentControl
55
56
  this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
56
57
  this.selectedColor = this.DEFAULT_COLOR
57
58
  this.selectedFont = this.DEFAULT_FONT
59
+ this.fontSelectorId = 'rteFontSelector' + Math.floor(Math.random() * 1000 + 1)
58
60
 
59
61
  this.colorPicker = document.getElementById('rteColorInput')
60
62
  this.colorPicker.addEventListener('change', this.colorChanged.bind(this))
@@ -109,15 +111,15 @@ export default class RichTextComponentController implements ng.IComponentControl
109
111
  this.applyColor()
110
112
  }
111
113
 
112
- protected fontSelected(font: google.fonts.WebfontFamily): void {
113
- if (font.family) {
114
+ protected fontSelected(fontFamily: string): void {
115
+ if (fontFamily) {
114
116
 
115
117
  this.$rootScope.$broadcast('richTextToolbarContainer:closeContainer')
116
118
  const fontAtributor = Quill.import('attributors/style/font')
117
- fontAtributor.whitelist = [font.family]
118
- this.updateFontDisplay(font.family)
119
+ fontAtributor.whitelist = [fontFamily]
120
+ this.updateFontDisplay(fontFamily)
119
121
  Quill.register(fontAtributor, true)
120
- this.editor.format('font', font.family)
122
+ this.editor.format('font', fontFamily)
121
123
 
122
124
  this.sanitizeContents()
123
125
  }