@mediafly/js-ui 47.2.1-beta.1 → 47.3.1-2

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 (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/auto-complete/auto-complete.component.html +2 -1
  3. package/lib/font-selector/font-selector.d.ts +41 -8
  4. package/lib/font-selector/font-selector.html +67 -13
  5. package/lib/font-selector/font-selector.js +193 -19
  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/localization/index.strings.json +3 -1
  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/tsconfig.deploy.tsbuildinfo +19 -31
  22. package/package.json +1 -1
  23. package/src/components/auto-complete/auto-complete.component.html +2 -1
  24. package/src/components/auto-complete/auto-complete.component.less +2 -1
  25. package/src/components/font-selector/font-selector.html +67 -13
  26. package/src/components/font-selector/font-selector.less +121 -0
  27. package/src/components/font-selector/font-selector.ts +214 -18
  28. package/src/components/font-selector/google-webfonts-api.backend.ts +1 -1
  29. package/src/components/font-selector/google-webfonts-api.service.ts +10 -2
  30. package/src/components/font-selector/webfont-loader.service.ts +2 -2
  31. package/src/components/index.less +1 -1
  32. package/src/components/localization/index.strings.json +3 -1
  33. package/src/components/rich-text/index.ts +0 -1
  34. package/src/components/rich-text/rich-text.component.html +6 -14
  35. package/src/components/rich-text/rich-text.component.less +5 -1
  36. package/src/components/rich-text/rich-text.component.ts +7 -5
  37. package/tsconfig.tsbuildinfo +46 -63
  38. package/lib/rich-text/rich-text-toolbar-container.component.d.ts +0 -16
  39. package/lib/rich-text/rich-text-toolbar-container.component.html +0 -12
  40. package/lib/rich-text/rich-text-toolbar-container.component.js +0 -75
  41. package/lib/rich-text/rich-text-toolbar-container.component.js.map +0 -1
  42. package/src/components/rich-text/rich-text-toolbar-container.component.html +0 -12
  43. package/src/components/rich-text/rich-text-toolbar-container.component.ts +0 -66
  44. 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,245 @@ 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
18
+ @Input('<') inputId!: string
19
+ @Input('<') isDisabled?: boolean
20
+ @Input('<') isRequired?: boolean
21
+ @Input('=?') fontFamily?: string
22
+
23
+ @Output('&?') onFontSelect?: (param: { fontFamily: string }) => void
22
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 popularFonts: string[]
36
+ protected popularFontsText: string
37
+ protected matches: string[] = []
38
+ protected minLength: number = 2
39
+ protected requiredText: string
40
+ protected showPopular: boolean = true
41
+ protected whatAreGoogleFonts: string
42
+
43
+ private debouncedFetchAndSetMatches = _.debounce(() => this.fetchAndSetMatches(), this.delay)
44
+ private inputElement: HTMLElement
45
+ private observer: MutationObserver
24
46
 
25
47
  constructor (
48
+ @Inject('$document') private $document: ng.IDocumentService,
49
+ @Inject('$element') private $element: ng.IAugmentedJQuery,
50
+ @Inject('$timeout') private $timeout: ng.ITimeoutService,
51
+ @Inject('$q') private $q: ng.IQService,
26
52
  @Inject('googleWebfontsApiService') private googleWebfontsApiService: GoogleWebfontsApiService,
27
53
  @Inject('translateFactory') private translateFactory: TranslateFactory,
28
54
  @Inject('webfontLoaderService') private webfontLoaderService: WebfontLoaderService,
29
55
  ) {}
30
56
 
31
- protected googleFonts: google.fonts.WebfontFamily[]
57
+ $onDestroy() {
58
+ if (this.keyEventElement) {
59
+ this.keyEventElement.removeEventListener('input', this.debouncedFetchAndSetMatches)
60
+ this.keyEventElement.removeEventListener('keydown', this.onKeyDown)
61
+ }
62
+
63
+ const body = (this.$document[0] as Document).body
64
+ body.removeEventListener('click', this.onClickElsewhere)
65
+
66
+ this.observer.disconnect()
67
+ }
32
68
 
33
69
  $onInit() {
34
- // set label text
35
- this.placeholderText = this.translateFactory.instant('JSUI.SEARCH_FONTS')
70
+ if (!this.inputId) { throw new Error(`You must provide a string to key-event-element-id on the FontSelector.`) }
71
+ // set labels and text
72
+ this.placeholderText = this.translateFactory.instant('JSUI.SEARCH_ALL_GOOGLE_FONTS')
73
+ this.popularFontsText = this.translateFactory.instant('JSUI.POPULAR_FONTS')
74
+ this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
75
+ this.whatAreGoogleFonts = this.translateFactory.instant('JSUI.WHAT_ARE_GOOGLE_FONTS')
76
+
77
+ // init list of popylar fonts
78
+ this.googleWebfontsApiService.getFontList('popularity')
79
+ .then(popularList => {
80
+ this.popularFonts = popularList.map(f => f.family)
81
+ this.popularFonts = this.popularFonts.slice(0, 50)
82
+ this.webfontLoaderService.loadFonts(this.popularFonts)
83
+ this.matches = this.popularFonts
84
+ })
36
85
 
37
86
  // init list of google fonts
38
87
  this.googleWebfontsApiService.getFontList()
39
- .then(fontList => { this.googleFonts = fontList })
88
+ .then(fontList => {
89
+ this.googleFonts = fontList.map(f => f.family)
90
+ this.loadingFonts = false
91
+ })
92
+
93
+ const body = (this.$document[0] as Document).body
94
+ body.addEventListener('click', this.onClickElsewhere)
95
+
96
+ // Set up an observer that will find the input element and attach events when it is present.
97
+ this.observer = new MutationObserver(() => {
98
+ // expect the tag-input component to be defined in a div with the id autocomplete-tag-lookup
99
+ // this allows us to more reliably find the input to listen to when there are multiple instances of this combination
100
+ this.inputElement = this.$element.parent().find(`#${this.inputId}`)[0]
101
+ if (this.inputElement) {
102
+ this.keyEventElement = this.inputElement as HTMLInputElement
103
+ this.keyEventElement.addEventListener('input', this.debouncedFetchAndSetMatches)
104
+ this.keyEventElement.addEventListener('keydown', this.onKeyDown)
105
+ this.observer.disconnect()
106
+ }
107
+ })
108
+
109
+ this.observer.observe(body, { attributes: true, childList: true, characterData: false, subtree: true })
110
+ }
111
+
112
+ protected clearInput($event): void {
113
+ this.inputValue = ''
114
+ this.matches = this.popularFonts
115
+ this.showPopular = true
116
+ $event.stopPropagation()
117
+ }
118
+
119
+ protected clickSelect($event): void {
120
+ if (this.isDisabled) { return }
121
+ this.isDropdownVisible = !this.isDropdownVisible
122
+ if (this.isDropdownVisible) {
123
+ this.$timeout(() => {
124
+ this.inputElement.focus()
125
+ }, 250)
126
+ }
127
+ $event.stopPropagation()
128
+ }
129
+
130
+ // When the user mouses over the dropdown, we should remove any keyboard
131
+ // highlighting, since the mouse hover provides it too.
132
+ dropdownWasMousedOver() {
133
+ this.interactionMode = 'mouse'
134
+ this.kbSelectedIndex = -1
135
+ }
136
+
137
+ protected inputClick($event): void{
138
+ $event.stopPropagation()
139
+ }
140
+
141
+ protected inputValueWasChanged() {
142
+ this.debouncedFetchAndSetMatches()
143
+ }
144
+
145
+ protected matchWasSelected(match: string) {
146
+ this.matches = this.popularFonts
147
+ this.showPopular = true
148
+ this.kbSelectedIndex = -1
149
+ this.inputValue = ''
150
+ this.fontFamily = match
151
+ this.isDropdownVisible = false
152
+ if (this.onFontSelect) {
153
+ this.onFontSelect({fontFamily: this.fontFamily})
154
+ }
40
155
  }
41
156
 
42
- protected onFontLookup(value: string): AutoCompleteMatchObject<google.fonts.WebfontFamily>[] {
157
+ protected onFontLookup(value: string): ng.IPromise<string[]> {
43
158
 
159
+ value = value.toLocaleLowerCase()
160
+
161
+ // const fonts: google.fonts.WebfontFamily[] = []
44
162
  const fonts = this.googleFonts.filter(font => {
45
- return font.family.toLowerCase().includes(value.toLowerCase())
163
+ return font.toLowerCase().includes(value)
46
164
  })
47
165
 
48
166
  // load this set with the api service
49
167
  this.webfontLoaderService.loadFonts(fonts)
50
168
 
169
+ return this.$q.resolve(fonts)
170
+ }
171
+
172
+ private fetchAndSetMatches(): void {
173
+
174
+ this.isFetching = true
175
+
176
+ const input = this.inputValue || (this.keyEventElement ? this.keyEventElement.value : '')
177
+
178
+ if (input.length < this.minLength) {
179
+ this.$timeout(() => {
180
+ this.matches = this.popularFonts
181
+ this.showPopular = true
182
+ })
183
+ return
184
+ }
51
185
 
52
- return fonts.map(font => ({
53
- cssStyle: { 'font-family': font.family } as FontFamilyStyle,
54
- displayValue: font.family,
55
- value: font
56
- }))
186
+ this.isFetching = true
57
187
 
188
+ // Wrap the entire fetch in a timeout so that fetching callbacks will
189
+ // be called correctly while the async part happens.
190
+ this.$timeout(() => {
191
+ this.$q.when(this.onFontLookup(input))
192
+ .then(matches => {
193
+ this.matches = matches
194
+ this.showPopular = false
195
+ this.isFetching = false
196
+ })
197
+ })
58
198
  }
59
199
 
60
- protected onSelect(font: google.fonts.WebfontFamily) {
61
- this.onFontSelect({ font })
200
+ private onClickElsewhere = ($event: MouseEvent) => {
201
+
202
+ this.$timeout(() => {
203
+ this.isDropdownVisible = false
204
+ })
62
205
  }
206
+
207
+ private onKeyDown = ($event: KeyboardEvent) => this.$timeout(() => {
208
+
209
+ this.interactionMode = 'keyboard'
210
+
211
+ // Enter with no selection: let the $event through
212
+ if ($event.key === 'Enter' && this.kbSelectedIndex === -1) { return }
213
+
214
+ // If the dropdown is closed, all we can do is arrow down to open the thing
215
+ if (this.matches.length === 0 && $event.key !== 'ArrowDown') { return }
216
+
217
+ // Escape: close the dropdown
218
+ if ($event.key === 'Escape') {
219
+ this.matches = this.popularFonts
220
+ this.showPopular = true
221
+ }
222
+
223
+ // Arrow down with dropdown closed: fetch matches
224
+ if ($event.key === 'ArrowDown' && this.matches.length === 0) {
225
+ this.fetchAndSetMatches()
226
+ }
227
+
228
+ // Arrow keys with dropdown open: move the selection highlight
229
+ if ($event.key === 'ArrowDown' && this.matches.length > 0) {
230
+ const idx = Math.min(this.kbSelectedIndex + 1, this.matches.length - 1)
231
+ this.kbSelectedIndex = idx
232
+ this.scrollToMatch(idx)
233
+ }
234
+
235
+ if ($event.key === 'ArrowUp') {
236
+ const idx = Math.max(this.kbSelectedIndex - 1, 0)
237
+ this.kbSelectedIndex = idx
238
+ this.scrollToMatch(idx)
239
+ }
240
+
241
+ // Enter with a selection: set the selection to the currently highlighted match
242
+ if ($event.key === 'Enter' && this.kbSelectedIndex > -1) {
243
+ const match = this.matches[this.kbSelectedIndex]
244
+ this.matchWasSelected(match)
245
+ $event.preventDefault()
246
+ }
247
+
248
+ $event.stopPropagation()
249
+ })
250
+
251
+ private scrollToMatch(index: number) {
252
+
253
+ const row = this.$element.find('.c-font-selector__match-row')[index] as HTMLDivElement
254
+ if (row) {
255
+ row.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
256
+ }
257
+ }
258
+
63
259
  }
@@ -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';
@@ -30,11 +30,12 @@
30
30
  "NO": "No",
31
31
  "OK_GOT_IT": "OK, got it",
32
32
  "PDF": "PDF",
33
+ "POPULAR_FONTS": "Popular Fonts",
33
34
  "POWERPOINT": "PowerPoint",
34
35
  "PRIVACY_POLICY": "Privacy Policy",
35
36
  "RECENT_CHANGES": "Recent Changes",
36
37
  "REQUIRED": "Required",
37
- "SEARCH_FONTS": "Search fonts",
38
+ "SEARCH_ALL_GOOGLE_FONTS": "Search all Google fonts",
38
39
  "STATUS_CHECK": "Status Check",
39
40
  "SUPPORT": "Need help?",
40
41
  "TERMS_OF_USE": "Terms of Use",
@@ -42,6 +43,7 @@
42
43
  "UNKNOWN": "Unknown",
43
44
  "USER": "User",
44
45
  "VIDEO": "Video",
46
+ "WHAT_ARE_GOOGLE_FONTS": "What are Google Fonts?",
45
47
  "WORD_DOC": "Word document",
46
48
  "YES": "Yes",
47
49
  "ZIP": "ZIP file"
@@ -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
  }