@mediafly/js-ui 50.2.0 → 50.2.1-1

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,4 +1,4 @@
1
- <div id="toolbar" class="c-rich-text">
1
+ <div id="{{ $ctrl.toolbarId }}" class="c-rich-text">
2
2
 
3
3
  <span ng-if="$ctrl.allowFontSelection" class="ql-formats c-rich-text-font-container">
4
4
  <mfly:font-selector
@@ -9,7 +9,7 @@
9
9
  </span>
10
10
 
11
11
  <span class="ql-formats">
12
- <select id="editorSize" class="ql-size">
12
+ <select id="{{ $ctrl.editorSizeId }}" class="ql-size">
13
13
  <option value="10px" data-value="10px">10px</option>
14
14
  <option value="12px" data-value="12px">12px</option>
15
15
  <option value="14px" data-value="14px">14px</option>
@@ -22,7 +22,7 @@
22
22
 
23
23
  <!-- ng show for event handler -->
24
24
  <span ng-show="$ctrl.allowColorSelection" class="ql-formats">
25
- <input id="rteColorInput"
25
+ <input id="{{ $ctrl.colorInputId }}"
26
26
  type="color"
27
27
  ng-model="$ctrl.selectedColor">
28
28
  </span>
@@ -1,9 +1,11 @@
1
+ // tslint:disable: max-file-line-count
1
2
  import angular, { sanitize } from 'angular'
2
3
  import _ from 'lodash'
3
- import Quill from 'quill'
4
- import $ from 'jquery'
5
- import { FontFamilyStyle } from '../font-selector/font-selector'
4
+ import Quill, { Parchment, Range } from 'quill'
5
+ import { Delta, EmitterSource } from 'quill/core'
6
6
  import { Component, Inject, Input } from '../decorators'
7
+ import type { TranslateFactory } from '../translate/translate-factory'
8
+ import { v4 as uuidv4 } from 'uuid'
7
9
 
8
10
  // text editor requires sanitization but also needs to allow for style attributes which are removed by default
9
11
  angular.module('app').config(['$sanitizeProvider', ($sanitizeProvider: ng.sanitize.ISanitizeProvider) => {
@@ -24,105 +26,135 @@ export default class RichTextComponentController implements ng.IComponentControl
24
26
  @Input() allowFontSelection?: boolean
25
27
  @Input() isRequired!: boolean
26
28
 
27
- protected cachedSelection?: { index: number; length: number; }
28
- protected fontStyle?: FontFamilyStyle
29
+ protected cachedSelection?: Range | null
30
+ protected colorInputId: string
31
+ protected editorSizeId: string
29
32
  protected fontSelectorId: string
30
33
  protected requiredText: string
31
34
  protected selectedColor: string
32
35
  protected selectedFont: string
36
+ protected toolbarId: string
33
37
  protected validationForm: ng.IFormController
34
38
 
35
- private colorPicker
36
- private editor
39
+ private colorPicker: HTMLElement | null
40
+ private editor: Quill
37
41
  private ngModelCtrl: ng.INgModelController
38
42
 
39
- private debouncedOnTextChange = _.debounce((delta, oldContents, source) => this.onTextChange(delta, oldContents, source), 250)
43
+ private debouncedSanitizeAndValidate = _.debounce(() => this.sanitizeAndValidate(), 250)
40
44
 
41
45
  private DEFAULT_COLOR = '#535353'
42
46
  private DEFAULT_FONT = 'Roboto'
43
47
  private DEFAULT_SIZE = '14px'
44
48
 
49
+ private HEADING_1_COLOR = '#535353'
50
+ private HEADING_1_FONT = 'Poppins'
51
+ private HEADING_1_SIZE = '24px'
52
+
53
+ private HEADING_2_COLOR = '#535353'
54
+ private HEADING_2_FONT = 'Poppins'
55
+ private HEADING_2_SIZE = '14px'
56
+
45
57
  constructor(
46
58
  @Inject('$element') private $element: ng.IAugmentedJQuery,
47
59
  @Inject('$rootScope') private $rootScope: JSUIRootScope,
48
60
  @Inject('$sanitize') private $sanitize: sanitize.ISanitizeService,
49
61
  @Inject('$timeout') private $timeout: ng.ITimeoutService,
50
- @Inject('translateFactory') private translateFactory
51
- ) {}
62
+ @Inject('translateFactory') private translateFactory: TranslateFactory,
63
+ ) { }
52
64
 
53
65
  $onChanges(changes: { isRequired?: ng.IChangesObject<boolean> }) {
66
+
54
67
  if (!changes.isRequired) { return }
55
68
  if (changes.isRequired.currentValue === changes.isRequired.previousValue) { return }
56
69
 
57
- this.manageValidity()
70
+ this.checkValidity()
58
71
  }
59
72
 
60
73
  $onDestroy() {
61
- this.editor.off('text-change', this.debouncedOnTextChange)
62
- this.colorPicker.removeEventListener('change', this.colorChanged.bind(this))
63
- this.colorPicker.removeEventListener('click', this.colorInputOpened.bind(this))
74
+
75
+ this.editor.off('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
76
+ this.colorPicker?.removeEventListener('change', this.colorChanged.bind(this))
77
+ this.colorPicker?.removeEventListener('click', this.colorInputOpened.bind(this))
64
78
  }
65
79
 
66
80
  $onInit() {
81
+
67
82
  this.requiredText = this.translateFactory.instant('JSUI.REQUIRED')
68
- this.selectedColor = this.DEFAULT_COLOR
69
- this.selectedFont = this.DEFAULT_FONT
70
- this.fontSelectorId = 'rteFontSelector' + Math.floor(Math.random() * 1000 + 1)
71
83
 
72
- this.colorPicker = document.getElementById('rteColorInput')
73
- this.colorPicker.addEventListener('change', this.colorChanged.bind(this))
74
- this.colorPicker.addEventListener('click', this.colorInputOpened.bind(this))
84
+ this.colorInputId = 'rteColorInput-' + uuidv4()
85
+ this.editorSizeId = 'rteEditorSize-' + uuidv4()
86
+ this.fontSelectorId = 'rteFontSelector-' + uuidv4()
87
+ this.toolbarId = 'rteToolbar-' + uuidv4()
88
+
89
+ this.$timeout(() => {
90
+ this.colorPicker = document.getElementById(this.colorInputId)
91
+ this.colorPicker?.addEventListener('change', this.colorChanged.bind(this))
92
+ this.colorPicker?.addEventListener('click', this.colorInputOpened.bind(this))
75
93
 
76
- // programatically reset size
77
- $('.ql-size').val(this.DEFAULT_SIZE)
94
+ this.updateFontPicker(this.DEFAULT_FONT)
95
+ this.updateSizePicker(this.DEFAULT_SIZE)
96
+ this.updateColorPicker(this.DEFAULT_COLOR)
97
+ })
78
98
  }
79
99
 
80
100
  $postLink() {
81
101
 
82
- Quill.register(Quill.import('attributors/class/background'), true)
83
- Quill.register(Quill.import('attributors/style/color'), true)
102
+ Quill.register(Quill.import('attributors/class/background') as Parchment.Attributor, true)
103
+ Quill.register(Quill.import('attributors/style/color') as Parchment.Attributor, true)
84
104
 
85
- const fontStyle = Quill.import('attributors/style/font')
86
- fontStyle.whitelist = null // fonts not in the allow-list get dropped on other edits (CE-6314)
105
+ const fontStyle = Quill.import('attributors/style/font') as Parchment.Attributor
106
+ // Setting the whitelist to undefined allows all fonts. (We don't know what fonts Google Fonts will give us.)
107
+ fontStyle.whitelist = undefined
87
108
  Quill.register(fontStyle, true)
88
109
 
89
- const fontSizeArr = ['10px','12px','14px','16px','20px','24px','32px','42px','54px','68px','84px','98px']
90
- const Size = Quill.import('attributors/style/size')
91
- Size.whitelist = fontSizeArr
92
- Quill.register(Size, true)
110
+ const fontSizeArr = ['10px', '12px', '14px', '16px', '20px', '24px', '32px', '42px', '54px', '68px', '84px', '98px']
111
+ const size = Quill.import('attributors/style/size') as Parchment.Attributor
112
+ size.whitelist = fontSizeArr
113
+ Quill.register(size, true)
93
114
 
94
115
  const options = {
95
116
  modules: {
96
- toolbar: '#toolbar'
117
+ toolbar: `#${this.toolbarId}`,
97
118
  },
98
119
  theme: 'snow',
99
120
  }
100
121
 
101
- this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
122
+ this.$timeout(() => {
123
+ this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
102
124
 
103
- // Disable spellcheck because of a bad bug that deletes text (CE-4692).
104
- this.editor.root.setAttribute('spellcheck', false)
125
+ // Disable spellcheck because of a bad bug that deletes text (CE-4692).
126
+ this.editor.root.setAttribute('spellcheck', 'false')
105
127
 
106
- this.editor.on('text-change', this.debouncedOnTextChange)
107
- this.editor.on('selection-change', this.selectionChange.bind(this))
128
+ this.editor.on('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
129
+ this.editor.on('selection-change', this.selectionChange.bind(this))
130
+ })
108
131
 
109
132
  this.ngModelCtrl.$render = () => {
110
- if (!this.ngModelCtrl.$viewValue) {
111
- this.editor.setText('\n')
112
- return
113
- }
114
-
115
- this.editor.root.innerHTML = this.ngModelCtrl.$viewValue
133
+ this.$timeout(() => {
134
+ if (!this.ngModelCtrl.$viewValue) {
135
+ this.editor.setText('\n')
136
+ return
137
+ }
138
+
139
+ this.editor.root.innerHTML = this.ngModelCtrl.$viewValue
140
+ })
116
141
  }
117
-
118
142
  }
119
143
 
120
144
  protected colorChanged() {
121
- this.applyColor()
145
+
146
+ // Re-apply the text selection that was made before selecting a color,
147
+ // as the act of hiding some browsers' color inputs can change the selected text
148
+ if (this.cachedSelection) {
149
+ this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
150
+ }
151
+ this.editor.format('color', this.selectedColor)
152
+ this.debouncedSanitizeAndValidate()
122
153
  }
123
154
 
124
155
  protected colorInputOpened() {
125
- this.cacheSelection()
156
+
157
+ this.cachedSelection = this.editor.getSelection()
126
158
  }
127
159
 
128
160
  protected fontSelected(fontFamily: string): void {
@@ -130,141 +162,291 @@ export default class RichTextComponentController implements ng.IComponentControl
130
162
  if (!fontFamily) { return }
131
163
 
132
164
  this.$rootScope.$broadcast('richTextToolbarContainer:closeContainer')
133
- const fontAtributor = Quill.import('attributors/style/font')
134
- fontAtributor.whitelist = [fontFamily]
135
- this.updateFontDisplay(fontFamily)
136
- Quill.register(fontAtributor, true)
137
165
  this.editor.format('font', fontFamily)
138
166
 
139
- this.sanitizeContents()
167
+ this.debouncedSanitizeAndValidate()
140
168
  }
141
169
 
142
- protected manageValidity(): void {
170
+ /** The user entered/deleted/modified some text. Handle any formatting issues, then store the model. */
171
+ protected onTextChange(delta: Delta, _oldContents: Delta, source: EmitterSource): void {
143
172
 
144
- const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
173
+ if (source !== 'user') { return }
174
+
175
+ this.$timeout(() => {
176
+ // When we choose "Heading 1" or "Heading 2", we also need to set the font, size, and color.
177
+ this.fixHeadingFormat(delta)
178
+
179
+ // Quill's "Clear formatting" button leaves us inheriting styles from the CSS. We want to keep things explicit.
180
+ this.fixClearFormatting(delta)
145
181
 
146
- this.ngModelCtrl.$setValidity('required', isValid)
182
+ // Also, things like adding a line break can leave us with no style.
183
+ this.fixMissingFormats()
184
+ })
185
+
186
+ this.debouncedSanitizeAndValidate()
147
187
  }
148
188
 
149
- protected onTextChange(_delta, _oldContents, source): void {
189
+ /** The user moved the cursor. Fix missing formats and update the toolbar to reflect the current selection. */
190
+ protected selectionChange(range: Range, _oldRange: Range, source: EmitterSource): void {
150
191
 
151
192
  if (source !== 'user') { return }
193
+ if (!range) { return }
152
194
 
153
- const userClearedEditor = (this.editor.root.innerHTML === `<p><br></p>`)
154
- if (userClearedEditor) {
155
- // reset the color picker to the default by passing an undefined range
156
- this.editor.root.innerHTML = ''
157
- this.updateColorDisplay(undefined)
158
- this.ngModelCtrl.$setViewValue(undefined)
159
- this.manageValidity()
160
- this.formatToDefaults()
161
- return
195
+ this.fixMissingFormats()
196
+
197
+ this.$timeout(() => {
198
+ // Quill updates the toolbar to reflect most formatting (bold, italics, bullet points, etc.), but
199
+ // fonts, text size, and color are handled by plugins so we need to update those ourselves.
200
+ const format = this.editor.getFormat(range)
201
+ this.updateFontPicker(this.getFontFromFormat(format))
202
+ this.updateColorPicker(this.getColorFromFormat(format))
203
+ this.updateSizePicker(this.getSizeFromFormat(format))
204
+ })
205
+ }
206
+
207
+ private checkValidity(): void {
208
+
209
+ const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
210
+
211
+ this.$timeout(() => {
212
+ this.ngModelCtrl.$setValidity('required', isValid)
213
+ })
214
+ }
215
+
216
+ /**
217
+ * Quill's "Clear formatting" button leaves us with no font, size, or color, so the style is inherited from the CSS.
218
+ * We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
219
+ * reproduced elsewhere.
220
+ */
221
+ private fixClearFormatting(delta: Delta): void {
222
+
223
+ // Using the "Clear formatting" button creates a delta that sets font, size, and color to `null`. Detect any of those.
224
+ // (Usually you'd get all three together, but some might be missing from the delta if they were already clear,
225
+ // for example if we were editing an old Workspace Text Section that was created using an older version of this component.)
226
+ if (delta.ops.some((op) => op.retain && (
227
+ op.attributes?.font === null || op.attributes?.size === null || op.attributes?.color === null
228
+ ))) {
229
+ this.editor.format('font', this.DEFAULT_FONT)
230
+ this.updateFontPicker(this.DEFAULT_FONT)
231
+ this.editor.format('size', this.DEFAULT_SIZE)
232
+ this.updateSizePicker(this.DEFAULT_SIZE)
233
+ this.editor.format('color', this.DEFAULT_COLOR)
234
+ this.updateColorPicker(this.DEFAULT_COLOR)
162
235
  }
236
+ }
163
237
 
164
- this.sanitizeContents()
238
+ /**
239
+ * Quill's "Heading 1" and "Heading 2" just change the <p> to <h1> or <h2>. The inner <span> will still have a `style` on it,
240
+ * setting the font, size, and color. Quill prefers no `style` tags, so it expects the CSS to cover that. We use `style` for
241
+ * all our formatting, so we also need to define appropriate values for the Headings.
242
+ */
243
+ private fixHeadingFormat(delta: Delta): void {
244
+
245
+ // Look for an operation that sets a heading style (header = 1 or 2), or clears it (header = null)
246
+ const headingOp = delta.ops.find((op) => op.attributes?.header !== undefined)
247
+ if (!headingOp) { return }
165
248
 
166
249
  const selection = this.editor.getSelection()
167
250
  if (!selection) { return }
168
251
 
169
- const format = this.editor.getFormat(selection.index, 0)
170
- // the following checks for an empty formatting
171
- if (_.isEmpty(format)) {
172
- // if format is empty then set back to default styles
173
- this.formatToDefaults()
252
+ // The selection might cover multiple paragraphs, so get them all
253
+ let lines = this.editor.getLines(selection)
254
+ if (lines.length === 0) {
255
+ // The selection has zero length, so get the current paragraph
256
+ const line = this.editor.getLine(selection.index)
257
+ // (Perversely, `line` is an array, containing the actual line followed by a number :shrug:)
258
+ if (!line || !line[0]) { return }
259
+ lines = [line[0]]
174
260
  }
175
- }
176
261
 
177
- protected selectionChange(range, oldRange, source): void {
262
+ let font = this.DEFAULT_FONT
263
+ let size = this.DEFAULT_SIZE
264
+ let color = this.DEFAULT_COLOR
265
+
266
+ switch (headingOp.attributes?.header) {
267
+ case 1:
268
+ font = this.HEADING_1_FONT
269
+ size = this.HEADING_1_SIZE
270
+ color = this.HEADING_1_COLOR
271
+ break
272
+
273
+ case 2:
274
+ font = this.HEADING_2_FONT
275
+ size = this.HEADING_2_SIZE
276
+ color = this.HEADING_2_COLOR
277
+ break
278
+ }
178
279
 
179
- if (source !== 'user') { return }
180
- if (!range) { return }
280
+ for (const line of lines) {
281
+ const range = new Range(line.offset(), line.length())
282
+ this.editor.formatText(range, 'font', font)
283
+ this.editor.formatText(range, 'size', size)
284
+ this.editor.formatText(range, 'color', color)
285
+ }
181
286
 
182
- const leaf = this.editor.getLeaf(range.index)
183
- const font = this.getFontFromLeaf(leaf)
184
- const format = this.editor.getFormat(range)
287
+ this.updateFontPicker(font)
288
+ this.updateSizePicker(size)
289
+ this.updateColorPicker(color)
290
+ }
185
291
 
186
- this.updateColorDisplay(range)
292
+ /**
293
+ * Quill likes to default to no formatting: an empty paragraph has no font, size, or color, so the style is inherited
294
+ * from the CSS.
295
+ * We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
296
+ * reproduced elsewhere.
297
+ * We try to get the format from the previous line, or fall back to the default.
298
+ */
299
+ private fixMissingFormats(): void {
187
300
 
188
- // if get format is empty we can switch to the defaults
189
- if (!format.size) {
190
- $('.ql-size').val(this.DEFAULT_SIZE)
191
- $('#editorSize .ql-picker-label').attr('data-value',this.DEFAULT_SIZE)
192
- $('#editorSize .ql-picker-label').attr('data-label',this.DEFAULT_SIZE)
301
+ // When debugging this, it can be useful to add this to your CSS to highlight problems:
302
+ // .ql-editor { color: #f0f; font-family: 'Wingdings', sans-serif; font-size: 9px; }
303
+
304
+ const selection = this.editor.getSelection()
305
+ if (!selection || selection.length) {
306
+ // Some text is selected; we don't want to change this
307
+ return
193
308
  }
194
309
 
195
- if (font) {
196
- this.updateFontDisplay(font.replace(/"/g, ''))
310
+ const format = this.editor.getFormat()
311
+ if (format.font && format.size && format.color) {
312
+ // We are fully formatted; nothing more to do
197
313
  return
198
314
  }
199
315
 
316
+ // Copy missing format from the previous character (or the next, if we're at the start of the document)
317
+ const nearbyCharIndex = selection.index === 0 ? 1 : selection.index - 1
318
+ const nearbyRange: Range = {
319
+ index: nearbyCharIndex,
320
+ length: 0,
321
+ }
322
+ const nearbyFormat = this.editor.getFormat(nearbyRange)
323
+
324
+ this.editor.format('bold', nearbyFormat.bold)
325
+ this.editor.format('italic', nearbyFormat.italic)
326
+ this.editor.format('underline', nearbyFormat.underline)
327
+
200
328
  if (!format.font) {
201
- this.editor.format('font', this.DEFAULT_FONT)
329
+ const font = this.getFontFromFormat(nearbyFormat)
330
+ this.editor.format('font', font)
331
+ this.updateFontPicker(font)
202
332
  }
203
- }
204
333
 
205
- private applyColor(): void {
206
- // CE-3031: Re-apply the text selection that was made before selecting a color
207
- // as the act of hiding some browsers color inputs can change the selected text
208
- if (this.cachedSelection) {
209
- this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
334
+ if (!format.size) {
335
+ const size = this.getSizeFromFormat(nearbyFormat)
336
+ this.editor.format('size', size)
337
+ this.updateSizePicker(size)
210
338
  }
211
- this.editor.format('color', this.selectedColor)
212
- this.sanitizeContents()
213
- }
214
339
 
215
- private cacheSelection(): void {
216
- this.cachedSelection = this.editor.getSelection()
340
+ if (!format.color) {
341
+ const color = this.getColorFromFormat(nearbyFormat)
342
+ this.editor.format('color', color)
343
+ this.updateColorPicker(color)
344
+ }
217
345
  }
218
346
 
219
- private sanitizeContents(): void {
347
+ private getColorFromFormat(format: QuillFormat): string {
220
348
 
221
- const html = this.$sanitize(this.editor.root.innerHTML)
222
- this.ngModelCtrl.$setViewValue(html)
223
- this.manageValidity()
224
- }
349
+ if (!format.color) {
350
+ // We get no color if the default color is selected; or if the selection contains multiple colors, one of which is the default.
351
+ return this.DEFAULT_COLOR
352
+ }
353
+
354
+ if (typeof format.color === 'string') {
355
+ // The selected range is all the same color, which is not the default.
356
+ return format.color
357
+ }
225
358
 
226
- private formatToDefaults() {
359
+ if (Array.isArray(format.color)) {
360
+ // The selected range contains multiple colors, none of which are the default. Return the default, to be consistent with other multi-color selections.
361
+ return this.DEFAULT_COLOR
362
+ }
227
363
 
228
- this.updateFontDisplay(this.DEFAULT_FONT)
229
- this.editor.format('color', this.DEFAULT_COLOR)
230
- this.editor.format('size', this.DEFAULT_SIZE)
364
+ // Fall back to the default (should never get here)
365
+ return this.DEFAULT_COLOR
231
366
  }
232
367
 
233
- private getFontFromLeaf(leaf): string | undefined {
234
- if (!leaf) { return }
368
+ private getFontFromFormat(format: QuillFormat): string {
369
+
370
+ if (!format.font) {
371
+ // No font is defined for the selection, so show the default. This can happen if you're on a new empty line.
372
+ return this.DEFAULT_FONT
373
+ }
374
+
375
+ if (typeof format.font === 'string') {
376
+ // The range uses a single font.
377
+ return format.font
378
+ }
235
379
 
236
- if (!leaf[0].parent.domNode.style.fontFamily) { return }
380
+ if (Array.isArray(format.font)) {
381
+ // The selected range contains multiple fonts, so show blank.
382
+ return ''
383
+ }
237
384
 
238
- return leaf[0].parent.domNode.style.fontFamily
385
+ // Fall back to the default (should never get here)
386
+ return this.DEFAULT_FONT
239
387
  }
240
388
 
241
- private updateFontDisplay(fontFamily: string): void {
389
+ private getSizeFromFormat(format: QuillFormat): string {
390
+
391
+ if (!format.size) {
392
+ // We get no size if the default size is selected; or if the selection contains multiple sizes, one of which is the default.
393
+ return this.DEFAULT_SIZE
394
+ }
395
+
396
+ if (typeof format.size === 'string') {
397
+ // The selected range is all the same size, which is not the default.
398
+ return format.size
399
+ }
242
400
 
243
- this.selectedFont = fontFamily
244
- this.fontStyle = {
245
- 'font-family': fontFamily
401
+ if (Array.isArray(format.size)) {
402
+ // The selected range contains multiple sizes, none of which are the default. Return the first size in the array.
403
+ return format.size[0]
246
404
  }
405
+
406
+ // Fall back to the default (should never get here)
407
+ return this.DEFAULT_FONT
247
408
  }
248
409
 
249
- private updateColorDisplay(range: any): void {
410
+ private sanitizeAndValidate(): void {
250
411
 
251
- this.$timeout(() => {
252
- const format = this.editor.getFormat(range)
253
- const color = format.color
412
+ let html: string | undefined
254
413
 
255
- if (!color || _.isEmpty(color)) {
256
- this.selectedColor = this.DEFAULT_COLOR
414
+ // An empty Quill editor's html might be like:
415
+ // <p><span style="font-family: Roboto; font-size: 14px; color: rgb(83, 83, 83);"><span class="ql-cursor">&#65279;</span></span></p>
416
+ // Detect emptiness and return `undefined` instead, for easier "Required" validation.
417
+ if (!this.editor.getText().trim()) {
418
+ html = undefined
419
+ } else {
420
+ // Sometimes Quill's inner HTML includes its own cursor. We don't want to save that.
421
+ const withoutCursor = this.editor.root.innerHTML.replace(/\<span class="ql-cursor"\>.?\<\/span\>/, '')
422
+ html = this.$sanitize(withoutCursor)
423
+ }
257
424
 
258
- return
259
- }
260
- if (_.isArray(color)) {
425
+ this.ngModelCtrl.$setViewValue(html)
426
+ this.checkValidity()
427
+ }
261
428
 
262
- this.selectedColor = color[0]
263
- return
264
- }
429
+ /** Updates the color shown in the toolbar. Does not change the color being used in the text. */
430
+ private updateColorPicker(color: string): void {
265
431
 
266
- this.selectedColor = color
267
- })
432
+ this.selectedColor = color
433
+ }
268
434
 
435
+ /** Updates the font shown in the toolbar. Does not change the font being used in the text. */
436
+ private updateFontPicker(font: string): void {
437
+
438
+ this.selectedFont = font
439
+ }
440
+
441
+ /** Updates the size shown in the toolbar. Does not change the size being used in the text. */
442
+ private updateSizePicker(size: string): void {
443
+
444
+ this.$element.find('.ql-size').val(size)
445
+ this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-value', size)
446
+ this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-label', size)
269
447
  }
270
448
  }
449
+
450
+ interface QuillFormat {
451
+ [format: string]: unknown
452
+ }
@@ -1792,8 +1792,8 @@
1792
1792
  "affectsGlobalScope": false
1793
1793
  },
1794
1794
  "./src/components/dropdown/dropdown.ts": {
1795
- "version": "463ec52d6133c96d8ade1167d93c3e010c48389163b6a463fa3ed82cee3a7cca",
1796
- "signature": "810d32e0a6e6be00e7ee787ae89a970dd214af1bfa53e27fd5131e36e72a2910",
1795
+ "version": "0e8a3273816f29c1f04150fb68dc846776864aaa7120ef6b5113b4e5cb77504d",
1796
+ "signature": "84342560504a61d0bb90aa30b6ebd20155b855d9139c48818bf4715e74dddb35",
1797
1797
  "affectsGlobalScope": false
1798
1798
  },
1799
1799
  "./src/components/dropdown/index.ts": {
@@ -1827,7 +1827,7 @@
1827
1827
  "affectsGlobalScope": false
1828
1828
  },
1829
1829
  "./src/components/font-selector/webfont-loader.service.ts": {
1830
- "version": "ac4bb4369eda56a7901b75a295231edd4e746992c8e82f1ab1b28a736ad37c85",
1830
+ "version": "eb565e1c3ca5ae7fcdbe9fa6c81bd185f54752c52d49c25f6c8edb1b4b5299ca",
1831
1831
  "signature": "bbd2f564fd1f2863c05f27a96b089852de337861bb1f51f32c40bc496739604b",
1832
1832
  "affectsGlobalScope": false
1833
1833
  },
@@ -2791,7 +2791,7 @@
2791
2791
  "target": 2,
2792
2792
  "inlineSourceMap": false,
2793
2793
  "declarationMap": false,
2794
- "pathsBasePath": "C:/Work/Git/mediafly-js-ui",
2794
+ "pathsBasePath": "C:/Work/BitBucket/mediafly-js-ui",
2795
2795
  "configFilePath": "./tsconfig.json"
2796
2796
  },
2797
2797
  "referencedMap": {
@@ -5475,7 +5475,7 @@
5475
5475
  ],
5476
5476
  "./node_modules/@types/stylelint/index.d.ts": [
5477
5477
  "./node_modules/@types/stylelint/node_modules/globby/index.d.ts",
5478
- "./node_modules/@types/stylelint/node_modules/postcss/lib/postcss.d.ts"
5478
+ "./node_modules/postcss/lib/postcss.d.ts"
5479
5479
  ],
5480
5480
  "./node_modules/@types/stylelint/node_modules/globby/index.d.ts": [
5481
5481
  "./node_modules/fast-glob/out/index.d.ts"
@@ -5484,7 +5484,7 @@
5484
5484
  "./node_modules/@types/stylelint/node_modules/source-map/source-map.d.ts"
5485
5485
  ],
5486
5486
  "./node_modules/@types/uglify-js/index.d.ts": [
5487
- "./node_modules/@types/stylelint/node_modules/source-map/source-map.d.ts"
5487
+ "./node_modules/postcss/node_modules/source-map/source-map.d.ts"
5488
5488
  ],
5489
5489
  "./node_modules/@types/webpack-sources/index.d.ts": [
5490
5490
  "./node_modules/@types/node/index.d.ts",
@@ -5562,11 +5562,11 @@
5562
5562
  "./node_modules/@types/webpack/index.d.ts": [
5563
5563
  "./node_modules/@types/node/crypto.d.ts",
5564
5564
  "./node_modules/@types/node/index.d.ts",
5565
- "./node_modules/@types/stylelint/node_modules/source-map/source-map.d.ts",
5566
5565
  "./node_modules/@types/tapable/index.d.ts",
5567
5566
  "./node_modules/@types/uglify-js/index.d.ts",
5568
5567
  "./node_modules/@types/webpack-sources/index.d.ts",
5569
- "./node_modules/anymatch/index.d.ts"
5568
+ "./node_modules/anymatch/index.d.ts",
5569
+ "./node_modules/postcss/node_modules/source-map/source-map.d.ts"
5570
5570
  ],
5571
5571
  "./node_modules/@uirouter/angularjs/lib/directives/viewDirective.d.ts": [
5572
5572
  "./node_modules/@uirouter/angularjs/lib/directives/stateDirectives.d.ts",