@mediafly/js-ui 51.4.1 → 51.5.0-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.
- package/CHANGELOG.md +4 -0
- package/lib/dropdown-menu/dropdown-menu-toggle.js +13 -6
- package/lib/dropdown-menu/dropdown-menu-toggle.js.map +1 -1
- package/lib/font-selector/font-selector.d.ts +7 -3
- package/lib/font-selector/font-selector.html +7 -7
- package/lib/font-selector/font-selector.js +27 -12
- package/lib/font-selector/font-selector.js.map +1 -1
- package/lib/font-selector/google-webfonts-api.service.d.ts +4 -1
- package/lib/font-selector/google-webfonts-api.service.js +17 -3
- package/lib/font-selector/google-webfonts-api.service.js.map +1 -1
- package/lib/font-selector/webfont-loader.service.d.ts +1 -0
- package/lib/font-selector/webfont-loader.service.js +9 -0
- package/lib/font-selector/webfont-loader.service.js.map +1 -1
- package/lib/font-weight-selector/font-weight-selector.d.ts +30 -0
- package/lib/font-weight-selector/font-weight-selector.html +26 -0
- package/lib/font-weight-selector/font-weight-selector.js +162 -0
- package/lib/font-weight-selector/font-weight-selector.js.map +1 -0
- package/lib/font-weight-selector/index.d.ts +1 -0
- package/lib/font-weight-selector/index.js +4 -0
- package/lib/font-weight-selector/index.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/rich-text/rich-text.component.d.ts +9 -2
- package/lib/rich-text/rich-text.component.html +9 -2
- package/lib/rich-text/rich-text.component.js +45 -7
- package/lib/rich-text/rich-text.component.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +43 -11
- package/package.json +1 -1
- package/src/components/dropdown-menu/dropdown-menu-toggle.js +14 -6
- package/src/components/font-selector/font-selector.html +7 -7
- package/src/components/font-selector/font-selector.ts +31 -16
- package/src/components/font-selector/google-webfonts-api.service.ts +14 -0
- package/src/components/font-selector/webfont-loader.service.ts +12 -0
- package/src/components/font-weight-selector/font-weight-selector.html +26 -0
- package/src/components/font-weight-selector/font-weight-selector.less +48 -0
- package/src/components/font-weight-selector/font-weight-selector.ts +147 -0
- package/src/components/font-weight-selector/index.ts +1 -0
- package/src/components/index.less +1 -0
- package/src/components/index.ts +1 -0
- package/src/components/rich-text/rich-text.component.html +9 -2
- package/src/components/rich-text/rich-text.component.less +1 -0
- package/src/components/rich-text/rich-text.component.ts +49 -3
|
@@ -20,10 +20,10 @@ export default class FontSelectorController implements IComponentController {
|
|
|
20
20
|
@Input('<') isRequired?: boolean
|
|
21
21
|
@Input('=?') fontFamily?: string
|
|
22
22
|
|
|
23
|
-
@Output('&?') onFontSelect?: (param: { fontFamily: string }) => void
|
|
23
|
+
@Output('&?') onFontSelect?: (param: { fontFamily: string, fontWeightOptions?: number[] }) => void
|
|
24
24
|
|
|
25
25
|
protected delay: number = 500
|
|
26
|
-
protected googleFonts:
|
|
26
|
+
protected googleFonts: google.fonts.WebfontFamily[]
|
|
27
27
|
protected inputValue?: string
|
|
28
28
|
protected interactionMode: 'mouse' | 'keyboard' = 'mouse'
|
|
29
29
|
protected isDropdownVisible: boolean
|
|
@@ -86,7 +86,7 @@ export default class FontSelectorController implements IComponentController {
|
|
|
86
86
|
// init list of google fonts
|
|
87
87
|
this.googleWebfontsApiService.getFontList()
|
|
88
88
|
.then(fontList => {
|
|
89
|
-
this.googleFonts = fontList
|
|
89
|
+
this.googleFonts = fontList
|
|
90
90
|
this.loadingFonts = false
|
|
91
91
|
})
|
|
92
92
|
|
|
@@ -123,6 +123,8 @@ export default class FontSelectorController implements IComponentController {
|
|
|
123
123
|
this.$timeout(() => {
|
|
124
124
|
this.inputElement.focus()
|
|
125
125
|
}, 250)
|
|
126
|
+
} else {
|
|
127
|
+
this.resetDropdown()
|
|
126
128
|
}
|
|
127
129
|
$event.stopPropagation()
|
|
128
130
|
}
|
|
@@ -142,29 +144,42 @@ export default class FontSelectorController implements IComponentController {
|
|
|
142
144
|
this.debouncedFetchAndSetMatches()
|
|
143
145
|
}
|
|
144
146
|
|
|
145
|
-
protected
|
|
147
|
+
protected resetDropdown() {
|
|
148
|
+
this.isDropdownVisible = false
|
|
146
149
|
this.matches = this.popularFonts
|
|
147
150
|
this.showPopular = true
|
|
148
151
|
this.kbSelectedIndex = -1
|
|
149
152
|
this.inputValue = ''
|
|
150
|
-
this.fontFamily = match
|
|
151
|
-
this.isDropdownVisible = false
|
|
152
|
-
if (this.onFontSelect) {
|
|
153
|
-
this.onFontSelect({fontFamily: this.fontFamily})
|
|
154
|
-
}
|
|
155
153
|
}
|
|
156
154
|
|
|
157
|
-
protected
|
|
155
|
+
protected onFontSelected(fontFamily: string, $event?: MouseEvent) {
|
|
156
|
+
$event?.stopPropagation()
|
|
157
|
+
this.fontFamily = fontFamily
|
|
158
|
+
|
|
159
|
+
this.getFontWeightOptions(fontFamily)
|
|
160
|
+
.then((fontWeightOptions: number[]) => {
|
|
161
|
+
this.onFontSelect?.({ fontFamily, fontWeightOptions })
|
|
162
|
+
this.resetDropdown()
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
protected getFontWeightOptions(fontFamily: string | undefined): ng.IPromise<number[]> {
|
|
167
|
+
if (!fontFamily) { return this.$q.resolve([]) }
|
|
168
|
+
|
|
169
|
+
return this.googleWebfontsApiService.getFontVariants(fontFamily, this.googleFonts)
|
|
170
|
+
.then(variants => this.googleWebfontsApiService.sortFontWeightVariants(variants))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
protected onFontLookup(value: string): ng.IPromise<google.fonts.WebfontFamily[]> {
|
|
158
174
|
|
|
159
175
|
value = value.toLocaleLowerCase()
|
|
160
176
|
|
|
161
|
-
// const fonts: google.fonts.WebfontFamily[] = []
|
|
162
177
|
const fonts = this.googleFonts.filter(font => {
|
|
163
|
-
return font.toLowerCase().includes(value)
|
|
178
|
+
return font.family.toLowerCase().includes(value)
|
|
164
179
|
})
|
|
165
180
|
|
|
166
181
|
// load this set with the api service
|
|
167
|
-
this.webfontLoaderService.loadFonts(fonts)
|
|
182
|
+
this.webfontLoaderService.loadFonts(fonts.map(font => font.family))
|
|
168
183
|
|
|
169
184
|
return this.$q.resolve(fonts)
|
|
170
185
|
}
|
|
@@ -190,7 +205,7 @@ export default class FontSelectorController implements IComponentController {
|
|
|
190
205
|
this.$timeout(() => {
|
|
191
206
|
this.$q.when(this.onFontLookup(input))
|
|
192
207
|
.then(matches => {
|
|
193
|
-
this.matches = matches
|
|
208
|
+
this.matches = matches.map(match => match.family)
|
|
194
209
|
this.showPopular = false
|
|
195
210
|
this.isFetching = false
|
|
196
211
|
})
|
|
@@ -200,7 +215,7 @@ export default class FontSelectorController implements IComponentController {
|
|
|
200
215
|
private onClickElsewhere = ($event: MouseEvent) => {
|
|
201
216
|
|
|
202
217
|
this.$timeout(() => {
|
|
203
|
-
this.
|
|
218
|
+
this.resetDropdown()
|
|
204
219
|
})
|
|
205
220
|
}
|
|
206
221
|
|
|
@@ -241,7 +256,7 @@ export default class FontSelectorController implements IComponentController {
|
|
|
241
256
|
// Enter with a selection: set the selection to the currently highlighted match
|
|
242
257
|
if ($event.key === 'Enter' && this.kbSelectedIndex > -1) {
|
|
243
258
|
const match = this.matches[this.kbSelectedIndex]
|
|
244
|
-
this.
|
|
259
|
+
this.onFontSelected(match)
|
|
245
260
|
$event.preventDefault()
|
|
246
261
|
}
|
|
247
262
|
|
|
@@ -6,6 +6,7 @@ export default class GoogleWebfontsApiService {
|
|
|
6
6
|
|
|
7
7
|
constructor(
|
|
8
8
|
@Inject('$http') private $http: ng.IHttpService,
|
|
9
|
+
@Inject('$q') private $q: ng.IQService,
|
|
9
10
|
@Inject('apiSuccessHandler') private apiSuccessHandler: ApiSuccessHandler,
|
|
10
11
|
) { }
|
|
11
12
|
|
|
@@ -25,4 +26,17 @@ export default class GoogleWebfontsApiService {
|
|
|
25
26
|
})
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
// Get the available font variants for a given font family
|
|
30
|
+
getFontVariants(family: string, list?: google.fonts.WebfontFamily[]): ng.IPromise<string[]> {
|
|
31
|
+
return this.$q.resolve(list || this.getFontList())
|
|
32
|
+
.then(families => (families.find(opt => opt.family === family)?.variants || []))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Filter down the variants to just font weights and order them by ascending weight
|
|
36
|
+
sortFontWeightVariants(options: string[] | undefined): number[] {
|
|
37
|
+
return (options || [])
|
|
38
|
+
.filter(opt => !opt.includes('italic'))
|
|
39
|
+
.map(opt => opt === 'regular' ? 400 : parseInt(opt, 10))
|
|
40
|
+
.sort((a, b) => a - b)
|
|
41
|
+
}
|
|
28
42
|
}
|
|
@@ -39,4 +39,16 @@ export default class WebfontLoaderService {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
loadFontVariants(fontFamily: string, variants: string[]): void {
|
|
44
|
+
|
|
45
|
+
const fontVariants = [`${fontFamily}:${variants.join(',')}`]
|
|
46
|
+
|
|
47
|
+
WebFont.load({
|
|
48
|
+
google: {
|
|
49
|
+
families: fontVariants
|
|
50
|
+
},
|
|
51
|
+
timeout: 5000
|
|
52
|
+
})
|
|
53
|
+
}
|
|
42
54
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<button ng-click="$ctrl.clickSelect($event)" class="c-font-weight-selector__select">
|
|
2
|
+
<div class="fas fa-text-height c-font-weight-selector__select__icon"></div>
|
|
3
|
+
</button>
|
|
4
|
+
|
|
5
|
+
<div
|
|
6
|
+
ng-class="{'is-visible': $ctrl.isDropdownVisible}"
|
|
7
|
+
class="c-font-weight-selector__dropdown"
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
ng-mousemove="$ctrl.dropdownWasMousedOver($event)"
|
|
11
|
+
class="c-font-weight-selector__dropdown__matches"
|
|
12
|
+
>
|
|
13
|
+
<div
|
|
14
|
+
class="c-font-weight-selector__match-row"
|
|
15
|
+
ng-class="[
|
|
16
|
+
($ctrl.interactionMode === 'mouse') ? 'with-mouse' : 'with-keyboard',
|
|
17
|
+
{ 'is-selected': ($ctrl.kbSelectedIndex === $index) },
|
|
18
|
+
]"
|
|
19
|
+
ng-style="{'font-family': $ctrl.fontFamily, 'font-weight': variant}"
|
|
20
|
+
ng-click="$ctrl.variantWasSelected(variant)"
|
|
21
|
+
ng-repeat="variant in $ctrl.fontWeightOptions"
|
|
22
|
+
>
|
|
23
|
+
<span>{{ variant }}</span>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
@import '../less/variables/colors.less';
|
|
2
|
+
|
|
3
|
+
// Avoid alignment issues with the Quill styles
|
|
4
|
+
mfly\:font-weight-selector {
|
|
5
|
+
display: block;
|
|
6
|
+
float: left;
|
|
7
|
+
height: 24px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.ql-snow.ql-toolbar button.c-font-weight-selector__select {
|
|
11
|
+
padding: 1px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.c-font-weight-selector__select__icon {
|
|
15
|
+
padding-top: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.c-font-weight-selector__dropdown {
|
|
19
|
+
background-color: #fff;
|
|
20
|
+
border: 1px solid @color-gray-x-light;
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
box-shadow: @dropdown-box-shadow;
|
|
23
|
+
display: none;
|
|
24
|
+
max-height: 300px;
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 36px;
|
|
27
|
+
width: 100px;
|
|
28
|
+
z-index: 2;
|
|
29
|
+
|
|
30
|
+
&.is-visible {
|
|
31
|
+
display: block;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.c-font-weight-selector__dropdown__matches {
|
|
36
|
+
max-height: 250px;
|
|
37
|
+
overflow-y: auto;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.c-font-weight-selector__match-row {
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
padding: 5px 10px;
|
|
43
|
+
|
|
44
|
+
&.with-mouse:hover,
|
|
45
|
+
&.with-keyboard.is-selected {
|
|
46
|
+
background-color: @color-gray-xx-light;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Component, Inject, Input, Output } from '../decorators'
|
|
2
|
+
import WebfontLoaderService from '../font-selector/webfont-loader.service'
|
|
3
|
+
import { IComponentController } from 'angular'
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
selector: 'mflyFontWeightSelector',
|
|
7
|
+
template: require('./font-weight-selector.html')
|
|
8
|
+
})
|
|
9
|
+
export default class FontWeightSelectorController implements IComponentController {
|
|
10
|
+
|
|
11
|
+
@Input() fontFamily?: string
|
|
12
|
+
@Input() fontWeight?: string
|
|
13
|
+
@Input() fontWeightOptions?: string[]
|
|
14
|
+
|
|
15
|
+
@Output('&?') onFontWeightSelect?: (param: { fontWeight: string }) => void
|
|
16
|
+
|
|
17
|
+
protected interactionMode: 'mouse' | 'keyboard' = 'keyboard'
|
|
18
|
+
protected isDropdownVisible: boolean = false
|
|
19
|
+
protected kbSelectedIndex = -1
|
|
20
|
+
protected keyEventElement: HTMLElement | null = null
|
|
21
|
+
private observer: MutationObserver
|
|
22
|
+
|
|
23
|
+
constructor (
|
|
24
|
+
@Inject('$document') private $document: ng.IDocumentService,
|
|
25
|
+
@Inject('$scope') private $scope: ng.IScope,
|
|
26
|
+
@Inject('$element') private $element: ng.IAugmentedJQuery,
|
|
27
|
+
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
28
|
+
@Inject('webfontLoaderService') private webfontLoaderService: WebfontLoaderService,
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
$onDestroy() {
|
|
32
|
+
if (this.keyEventElement) {
|
|
33
|
+
this.keyEventElement.removeEventListener('keydown', this.onKeyDown)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const body = (this.$document[0] as Document).body
|
|
37
|
+
body.removeEventListener('click', this.onClickElsewhere)
|
|
38
|
+
|
|
39
|
+
this.observer.disconnect()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
$onInit() {
|
|
43
|
+
|
|
44
|
+
const body = (this.$document[0] as Document).body
|
|
45
|
+
body.addEventListener('click', this.onClickElsewhere)
|
|
46
|
+
|
|
47
|
+
this.kbSelectedIndex = this.fontWeightOptions?.indexOf(this.fontWeight || '') || -1
|
|
48
|
+
|
|
49
|
+
// Load preview fonts when the font family or weight options change
|
|
50
|
+
this.$scope.$watchCollection(() => [this.fontFamily, this.fontWeightOptions], () => {
|
|
51
|
+
if (this.fontFamily && this.fontWeightOptions?.length) {
|
|
52
|
+
this.webfontLoaderService.loadFontVariants(this.fontFamily, this.fontWeightOptions)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
this.observer = new MutationObserver(() => {
|
|
57
|
+
this.keyEventElement = this.$element.parent().find('.c-font-weight-selector__dropdown__matches')[0]
|
|
58
|
+
if (this.keyEventElement) {
|
|
59
|
+
this.keyEventElement.addEventListener('keydown', this.onKeyDown)
|
|
60
|
+
this.observer.disconnect()
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
this.observer.observe(body, { attributes: true, childList: true, characterData: false, subtree: true })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected clickSelect($event): void {
|
|
68
|
+
this.isDropdownVisible = !this.isDropdownVisible
|
|
69
|
+
if (this.isDropdownVisible) {
|
|
70
|
+
this.$timeout(() => {
|
|
71
|
+
this.keyEventElement?.focus()
|
|
72
|
+
}, 250)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$event.stopPropagation()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// When the user mouses over the dropdown, we should remove any keyboard
|
|
79
|
+
// highlighting, since the mouse hover provides it too.
|
|
80
|
+
dropdownWasMousedOver() {
|
|
81
|
+
this.interactionMode = 'mouse'
|
|
82
|
+
this.kbSelectedIndex = -1
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected variantWasSelected(variant: string) {
|
|
86
|
+
if (!this.fontFamily) { throw new Error('Font family is unexpectedly undefined.') }
|
|
87
|
+
|
|
88
|
+
this.isDropdownVisible = false
|
|
89
|
+
this.onFontWeightSelect?.({ fontWeight: variant })
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private onClickElsewhere = ($event: MouseEvent) => {
|
|
93
|
+
|
|
94
|
+
this.$timeout(() => {
|
|
95
|
+
this.isDropdownVisible = false
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private onKeyDown = ($event: KeyboardEvent) => this.$timeout(() => {
|
|
100
|
+
|
|
101
|
+
if (!this.fontFamily || !this.fontWeightOptions?.length) { return }
|
|
102
|
+
|
|
103
|
+
this.interactionMode = 'keyboard'
|
|
104
|
+
|
|
105
|
+
// Enter with no selection: let the $event through
|
|
106
|
+
if ($event.key === 'Enter' && this.kbSelectedIndex === -1) { return }
|
|
107
|
+
|
|
108
|
+
// If the dropdown is closed, all we can do is arrow down to open the thing
|
|
109
|
+
if (this.fontWeightOptions.length === 0 && $event.key !== 'ArrowDown') { return }
|
|
110
|
+
|
|
111
|
+
// Escape: close the dropdown
|
|
112
|
+
if ($event.key === 'Escape') {
|
|
113
|
+
this.isDropdownVisible = false
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Arrow keys with dropdown open: move the selection highlight
|
|
117
|
+
if ($event.key === 'ArrowDown') {
|
|
118
|
+
const idx = Math.min(this.kbSelectedIndex + 1, this.fontWeightOptions.length - 1)
|
|
119
|
+
this.kbSelectedIndex = idx
|
|
120
|
+
this.scrollToSelection(idx)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if ($event.key === 'ArrowUp') {
|
|
124
|
+
const idx = Math.max(this.kbSelectedIndex - 1, 0)
|
|
125
|
+
this.kbSelectedIndex = idx
|
|
126
|
+
this.scrollToSelection(idx)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Enter with a selection: set the selection to the currently highlighted match
|
|
130
|
+
if ($event.key === 'Enter' && this.kbSelectedIndex > -1) {
|
|
131
|
+
const selectedFontWeight = this.fontWeightOptions[this.kbSelectedIndex]
|
|
132
|
+
this.onFontWeightSelect?.({ fontWeight: selectedFontWeight })
|
|
133
|
+
this.isDropdownVisible = false
|
|
134
|
+
$event.preventDefault()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
$event.stopPropagation()
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
private scrollToSelection(index: number) {
|
|
141
|
+
|
|
142
|
+
const row = this.$element.find('.c-font-weight-selector__match-row')[index] as HTMLDivElement
|
|
143
|
+
row?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './font-weight-selector'
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@import './feedback/feedback';
|
|
11
11
|
@import './first-time-motivator/first-time-motivator';
|
|
12
12
|
@import './font-selector/font-selector';
|
|
13
|
+
@import './font-weight-selector/font-weight-selector';
|
|
13
14
|
@import './footer/footer';
|
|
14
15
|
@import './hierarchy/hierarchy';
|
|
15
16
|
@import './hover-tooltip/hover-tooltip';
|
package/src/components/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<mfly:font-selector
|
|
5
5
|
input-id="$ctrl.fontSelectorId"
|
|
6
6
|
font-family="$ctrl.selectedFont"
|
|
7
|
-
on-font-select="$ctrl.fontSelected(fontFamily)">
|
|
7
|
+
on-font-select="$ctrl.fontSelected(fontFamily, fontWeightOptions)">
|
|
8
8
|
</mfly:font-selector>
|
|
9
9
|
</span>
|
|
10
10
|
|
|
@@ -39,7 +39,14 @@
|
|
|
39
39
|
</span>
|
|
40
40
|
|
|
41
41
|
<span class="ql-formats">
|
|
42
|
-
<button class="ql-bold"></button>
|
|
42
|
+
<button class="ql-bold" ng-show="!$ctrl.selectedFontAvailableWeights || $ctrl.selectedFontAvailableWeights.length <= 1 || !$ctrl.allowFontSelection"></button>
|
|
43
|
+
<mfly:font-weight-selector
|
|
44
|
+
ng-if="$ctrl.selectedFontAvailableWeights && $ctrl.selectedFontAvailableWeights.length > 1 && $ctrl.allowFontSelection"
|
|
45
|
+
font-family="$ctrl.selectedFont"
|
|
46
|
+
font-weight="$ctrl.selectedFontWeight"
|
|
47
|
+
font-weight-options="$ctrl.selectedFontAvailableWeights"
|
|
48
|
+
on-font-weight-select="$ctrl.fontWeightSelected(fontWeight)"
|
|
49
|
+
></mfly:font-weight-selector>
|
|
43
50
|
<button class="ql-italic"></button>
|
|
44
51
|
<button class="ql-underline"></button>
|
|
45
52
|
</span>
|
|
@@ -144,6 +144,7 @@ rich-text {
|
|
|
144
144
|
.ql-bg-\#3d1466 { background-color: #3d1466; }
|
|
145
145
|
|
|
146
146
|
// Size option overrides
|
|
147
|
+
.ql-size { max-width: 60px; }
|
|
147
148
|
.ql-size .ql-picker-item:nth-child(1) { font-size: 6px; }
|
|
148
149
|
.ql-size .ql-picker-item:nth-child(2) { font-size: 7px; }
|
|
149
150
|
.ql-size .ql-picker-item:nth-child(3) { font-size: 8px; }
|
|
@@ -7,6 +7,8 @@ import type { TranslateFactory } from '../translate/translate-factory'
|
|
|
7
7
|
import { v4 as uuidv4 } from 'uuid'
|
|
8
8
|
import RichTextService from './rich-text.service'
|
|
9
9
|
import { IComponentController } from 'angular'
|
|
10
|
+
import { StyleAttributor, Scope } from 'parchment'
|
|
11
|
+
import GoogleWebfontsApiService from '../font-selector/google-webfonts-api.service'
|
|
10
12
|
|
|
11
13
|
@Component({
|
|
12
14
|
selector: 'richText',
|
|
@@ -29,6 +31,8 @@ export default class RichTextComponentController implements IComponentController
|
|
|
29
31
|
protected requiredText: string
|
|
30
32
|
protected selectedColor: string
|
|
31
33
|
protected selectedFont: string
|
|
34
|
+
protected selectedFontAvailableWeights: number[]
|
|
35
|
+
protected selectedFontWeight: number
|
|
32
36
|
protected toolbarId: string
|
|
33
37
|
protected validationForm: ng.IFormController
|
|
34
38
|
|
|
@@ -41,6 +45,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
41
45
|
private DEFAULT_COLOR = '#535353'
|
|
42
46
|
private DEFAULT_FONT = 'Roboto'
|
|
43
47
|
private DEFAULT_SIZE = '14px'
|
|
48
|
+
private DEFAULT_WEIGHT = 400
|
|
44
49
|
|
|
45
50
|
private HEADING_1_COLOR = '#535353'
|
|
46
51
|
private HEADING_1_FONT = 'Poppins'
|
|
@@ -54,6 +59,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
54
59
|
@Inject('$element') private $element: ng.IAugmentedJQuery,
|
|
55
60
|
@Inject('$rootScope') private $rootScope: JSUIRootScope,
|
|
56
61
|
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
62
|
+
@Inject('googleWebfontsApiService') private googleWebfontsApiService: GoogleWebfontsApiService,
|
|
57
63
|
@Inject('richTextService') private richTextService: RichTextService,
|
|
58
64
|
@Inject('translateFactory') private translateFactory: TranslateFactory,
|
|
59
65
|
) { }
|
|
@@ -82,6 +88,13 @@ export default class RichTextComponentController implements IComponentController
|
|
|
82
88
|
this.fontSelectorId = 'rteFontSelector-' + uuidv4()
|
|
83
89
|
this.toolbarId = 'rteToolbar-' + uuidv4()
|
|
84
90
|
|
|
91
|
+
// Populate the available font weights for the default font
|
|
92
|
+
if (this.allowFontSelection) {
|
|
93
|
+
this.googleWebfontsApiService.getFontVariants(this.DEFAULT_FONT)
|
|
94
|
+
.then(variants => this.googleWebfontsApiService.sortFontWeightVariants(variants))
|
|
95
|
+
.then(weights => this.selectedFontAvailableWeights = weights)
|
|
96
|
+
}
|
|
97
|
+
|
|
85
98
|
this.$timeout(() => {
|
|
86
99
|
this.colorPicker = document.getElementById(this.colorInputId)
|
|
87
100
|
this.colorPicker?.addEventListener('change', this.colorChanged.bind(this))
|
|
@@ -97,6 +110,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
97
110
|
|
|
98
111
|
Quill.register(Quill.import('attributors/class/background') as Parchment.Attributor, true)
|
|
99
112
|
Quill.register(Quill.import('attributors/style/color') as Parchment.Attributor, true)
|
|
113
|
+
Quill.register(new StyleAttributor('font-weight', 'font-weight', { scope: Scope.INLINE }), true)
|
|
100
114
|
|
|
101
115
|
const fontStyle = Quill.import('attributors/style/font') as Parchment.Attributor
|
|
102
116
|
// Setting the whitelist to undefined allows all fonts. (We don't know what fonts Google Fonts will give us.)
|
|
@@ -153,16 +167,27 @@ export default class RichTextComponentController implements IComponentController
|
|
|
153
167
|
this.cachedSelection = this.editor.getSelection()
|
|
154
168
|
}
|
|
155
169
|
|
|
156
|
-
protected fontSelected(fontFamily: string): void {
|
|
170
|
+
protected fontSelected(fontFamily: string, fontWeightOptions?: number[]): void {
|
|
157
171
|
|
|
158
172
|
if (!fontFamily) { return }
|
|
159
173
|
|
|
160
174
|
this.$rootScope.$broadcast('richTextToolbarContainer:closeContainer')
|
|
161
175
|
this.editor.format('font', `"${fontFamily}"`)
|
|
162
176
|
|
|
177
|
+
this.selectedFontAvailableWeights = fontWeightOptions || []
|
|
178
|
+
if (!fontWeightOptions?.includes(this.selectedFontWeight)) {
|
|
179
|
+
this.selectedFontWeight = this.DEFAULT_WEIGHT
|
|
180
|
+
this.editor.format('font-weight', undefined)
|
|
181
|
+
}
|
|
182
|
+
|
|
163
183
|
this.debouncedSanitizeAndValidate()
|
|
164
184
|
}
|
|
165
185
|
|
|
186
|
+
protected fontWeightSelected(fontWeight: number): void {
|
|
187
|
+
this.selectedFontWeight = fontWeight
|
|
188
|
+
this.editor.format('font-weight', fontWeight === this.DEFAULT_WEIGHT ? undefined : fontWeight)
|
|
189
|
+
}
|
|
190
|
+
|
|
166
191
|
/** The user entered/deleted/modified some text. Handle any formatting issues, then store the model. */
|
|
167
192
|
protected onTextChange(delta: Delta, oldContents: Delta, source: EmitterSource): void {
|
|
168
193
|
|
|
@@ -236,6 +261,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
236
261
|
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
237
262
|
this.editor.format('color', this.DEFAULT_COLOR)
|
|
238
263
|
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
264
|
+
this.editor.format('font-weight', undefined)
|
|
239
265
|
}
|
|
240
266
|
}
|
|
241
267
|
|
|
@@ -367,7 +393,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
367
393
|
}
|
|
368
394
|
|
|
369
395
|
const format = this.editor.getFormat()
|
|
370
|
-
if (format.font && format.size && format.color) {
|
|
396
|
+
if (format.font && format.size && format.color && format['font-weight']) {
|
|
371
397
|
// We are fully formatted; nothing more to do
|
|
372
398
|
return
|
|
373
399
|
}
|
|
@@ -406,6 +432,11 @@ export default class RichTextComponentController implements IComponentController
|
|
|
406
432
|
this.editor.format('color', color)
|
|
407
433
|
this.updateColorPicker(color)
|
|
408
434
|
}
|
|
435
|
+
|
|
436
|
+
if (!format['font-weight']) {
|
|
437
|
+
const fontWeight = this.getFontWeightFromFormat(nearbyFormat)
|
|
438
|
+
this.editor.format('font-weight', fontWeight === this.DEFAULT_WEIGHT ? undefined : fontWeight)
|
|
439
|
+
}
|
|
409
440
|
}
|
|
410
441
|
|
|
411
442
|
private getColorFromFormat(format: QuillFormat): string {
|
|
@@ -450,6 +481,15 @@ export default class RichTextComponentController implements IComponentController
|
|
|
450
481
|
return this.DEFAULT_FONT
|
|
451
482
|
}
|
|
452
483
|
|
|
484
|
+
private getFontWeightFromFormat(format: QuillFormat): number {
|
|
485
|
+
|
|
486
|
+
if (typeof format['font-weight'] === 'string') {
|
|
487
|
+
return parseInt(format['font-weight'], 10)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return this.DEFAULT_WEIGHT
|
|
491
|
+
}
|
|
492
|
+
|
|
453
493
|
/**
|
|
454
494
|
* Scans the entire text and returns an array of objects denoting which font is used for each range.
|
|
455
495
|
*/
|
|
@@ -534,7 +574,7 @@ export default class RichTextComponentController implements IComponentController
|
|
|
534
574
|
}
|
|
535
575
|
|
|
536
576
|
// Fall back to the default (should never get here)
|
|
537
|
-
return this.
|
|
577
|
+
return this.DEFAULT_SIZE
|
|
538
578
|
}
|
|
539
579
|
|
|
540
580
|
/**
|
|
@@ -599,6 +639,12 @@ export default class RichTextComponentController implements IComponentController
|
|
|
599
639
|
private updateFontPicker(font: string): void {
|
|
600
640
|
|
|
601
641
|
this.selectedFont = font
|
|
642
|
+
|
|
643
|
+
this.googleWebfontsApiService.getFontVariants(font)
|
|
644
|
+
.then(variants => this.googleWebfontsApiService.sortFontWeightVariants(variants))
|
|
645
|
+
.then(weights => {
|
|
646
|
+
this.selectedFontAvailableWeights = weights
|
|
647
|
+
})
|
|
602
648
|
}
|
|
603
649
|
|
|
604
650
|
/** Updates the size shown in the toolbar. Does not change the size being used in the text. */
|