@mediafly/js-ui 50.2.0 → 50.2.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.
- package/lib/font-selector/font-selector.js +1 -1
- package/lib/rich-text/rich-text.component.d.ts +38 -18
- package/lib/rich-text/rich-text.component.html +3 -3
- package/lib/rich-text/rich-text.component.js +205 -117
- package/lib/rich-text/rich-text.component.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +415 -6
- package/package.json +3 -2
- package/src/components/font-selector/font-selector.ts +1 -1
- package/src/components/less/vendor/quill.snow.css +6 -941
- package/src/components/rich-text/rich-text.component.html +3 -3
- package/src/components/rich-text/rich-text.component.ts +247 -131
- package/tsconfig.tsbuildinfo +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<div id="
|
|
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="
|
|
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="
|
|
25
|
+
<input id="{{ $ctrl.colorInputId }}"
|
|
26
26
|
type="color"
|
|
27
27
|
ng-model="$ctrl.selectedColor">
|
|
28
28
|
</span>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import angular, { sanitize } from 'angular'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import Quill from 'quill'
|
|
4
|
-
import
|
|
5
|
-
import { FontFamilyStyle } from '../font-selector/font-selector'
|
|
3
|
+
import Quill, { Parchment, Range } from 'quill'
|
|
4
|
+
import { Delta, EmitterSource } from 'quill/core'
|
|
6
5
|
import { Component, Inject, Input } from '../decorators'
|
|
6
|
+
import type { TranslateFactory } from '../translate/translate-factory'
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
7
8
|
|
|
8
9
|
// text editor requires sanitization but also needs to allow for style attributes which are removed by default
|
|
9
10
|
angular.module('app').config(['$sanitizeProvider', ($sanitizeProvider: ng.sanitize.ISanitizeProvider) => {
|
|
@@ -24,19 +25,21 @@ export default class RichTextComponentController implements ng.IComponentControl
|
|
|
24
25
|
@Input() allowFontSelection?: boolean
|
|
25
26
|
@Input() isRequired!: boolean
|
|
26
27
|
|
|
27
|
-
protected cachedSelection?:
|
|
28
|
-
protected
|
|
28
|
+
protected cachedSelection?: Range | null
|
|
29
|
+
protected colorInputId: string
|
|
30
|
+
protected editorSizeId: string
|
|
29
31
|
protected fontSelectorId: string
|
|
30
32
|
protected requiredText: string
|
|
31
33
|
protected selectedColor: string
|
|
32
34
|
protected selectedFont: string
|
|
35
|
+
protected toolbarId: string
|
|
33
36
|
protected validationForm: ng.IFormController
|
|
34
37
|
|
|
35
|
-
private colorPicker
|
|
36
|
-
private editor
|
|
38
|
+
private colorPicker: HTMLElement | null
|
|
39
|
+
private editor: Quill
|
|
37
40
|
private ngModelCtrl: ng.INgModelController
|
|
38
41
|
|
|
39
|
-
private
|
|
42
|
+
private debouncedSanitizeAndValidate = _.debounce(() => this.sanitizeAndValidate(), 250)
|
|
40
43
|
|
|
41
44
|
private DEFAULT_COLOR = '#535353'
|
|
42
45
|
private DEFAULT_FONT = 'Roboto'
|
|
@@ -47,82 +50,102 @@ export default class RichTextComponentController implements ng.IComponentControl
|
|
|
47
50
|
@Inject('$rootScope') private $rootScope: JSUIRootScope,
|
|
48
51
|
@Inject('$sanitize') private $sanitize: sanitize.ISanitizeService,
|
|
49
52
|
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
50
|
-
@Inject('translateFactory') private translateFactory
|
|
51
|
-
) {}
|
|
53
|
+
@Inject('translateFactory') private translateFactory: TranslateFactory,
|
|
54
|
+
) { }
|
|
52
55
|
|
|
53
56
|
$onChanges(changes: { isRequired?: ng.IChangesObject<boolean> }) {
|
|
57
|
+
|
|
54
58
|
if (!changes.isRequired) { return }
|
|
55
59
|
if (changes.isRequired.currentValue === changes.isRequired.previousValue) { return }
|
|
56
60
|
|
|
57
|
-
this.
|
|
61
|
+
this.checkValidity()
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
$onDestroy() {
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
this.colorPicker
|
|
65
|
+
|
|
66
|
+
this.editor.off('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
67
|
+
this.colorPicker?.removeEventListener('change', this.colorChanged.bind(this))
|
|
68
|
+
this.colorPicker?.removeEventListener('click', this.colorInputOpened.bind(this))
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
$onInit() {
|
|
72
|
+
|
|
67
73
|
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
74
|
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
+
this.colorInputId = 'rteColorInput-' + uuidv4()
|
|
76
|
+
this.editorSizeId = 'rteEditorSize-' + uuidv4()
|
|
77
|
+
this.fontSelectorId = 'rteFontSelector-' + uuidv4()
|
|
78
|
+
this.toolbarId = 'rteToolbar-' + uuidv4()
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
this.$timeout(() => {
|
|
81
|
+
this.colorPicker = document.getElementById(this.colorInputId)
|
|
82
|
+
this.colorPicker?.addEventListener('change', this.colorChanged.bind(this))
|
|
83
|
+
this.colorPicker?.addEventListener('click', this.colorInputOpened.bind(this))
|
|
84
|
+
|
|
85
|
+
this.updateFontPicker(this.DEFAULT_FONT)
|
|
86
|
+
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
87
|
+
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
88
|
+
})
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
$postLink() {
|
|
81
92
|
|
|
82
|
-
Quill.register(Quill.import('attributors/class/background'), true)
|
|
83
|
-
Quill.register(Quill.import('attributors/style/color'), true)
|
|
93
|
+
Quill.register(Quill.import('attributors/class/background') as Parchment.Attributor, true)
|
|
94
|
+
Quill.register(Quill.import('attributors/style/color') as Parchment.Attributor, true)
|
|
84
95
|
|
|
85
|
-
const fontStyle = Quill.import('attributors/style/font')
|
|
86
|
-
|
|
96
|
+
const fontStyle = Quill.import('attributors/style/font') as Parchment.Attributor
|
|
97
|
+
// Setting the whitelist to undefined allows all fonts. (We don't know what fonts Google Fonts will give us.)
|
|
98
|
+
fontStyle.whitelist = undefined
|
|
87
99
|
Quill.register(fontStyle, true)
|
|
88
100
|
|
|
89
|
-
const fontSizeArr = ['10px','12px','14px','16px','20px','24px','32px','42px','54px','68px','84px','98px']
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
Quill.register(
|
|
101
|
+
const fontSizeArr = ['10px', '12px', '14px', '16px', '20px', '24px', '32px', '42px', '54px', '68px', '84px', '98px']
|
|
102
|
+
const size = Quill.import('attributors/style/size') as Parchment.Attributor
|
|
103
|
+
size.whitelist = fontSizeArr
|
|
104
|
+
Quill.register(size, true)
|
|
93
105
|
|
|
94
106
|
const options = {
|
|
95
107
|
modules: {
|
|
96
|
-
toolbar:
|
|
108
|
+
toolbar: `#${this.toolbarId}`,
|
|
97
109
|
},
|
|
98
110
|
theme: 'snow',
|
|
99
111
|
}
|
|
100
112
|
|
|
101
|
-
this
|
|
113
|
+
this.$timeout(() => {
|
|
114
|
+
this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
|
|
102
115
|
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
// Disable spellcheck because of a bad bug that deletes text (CE-4692).
|
|
117
|
+
this.editor.root.setAttribute('spellcheck', 'false')
|
|
105
118
|
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
this.editor.on('text-change', (delta: Delta, oldContents, source) => { this.onTextChange(delta, oldContents, source) })
|
|
120
|
+
this.editor.on('selection-change', this.selectionChange.bind(this))
|
|
121
|
+
})
|
|
108
122
|
|
|
109
123
|
this.ngModelCtrl.$render = () => {
|
|
110
|
-
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
this.$timeout(() => {
|
|
125
|
+
if (!this.ngModelCtrl.$viewValue) {
|
|
126
|
+
this.editor.setText('\n')
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.editor.root.innerHTML = this.ngModelCtrl.$viewValue
|
|
131
|
+
})
|
|
116
132
|
}
|
|
117
|
-
|
|
118
133
|
}
|
|
119
134
|
|
|
120
135
|
protected colorChanged() {
|
|
121
|
-
|
|
136
|
+
|
|
137
|
+
// Re-apply the text selection that was made before selecting a color,
|
|
138
|
+
// as the act of hiding some browsers' color inputs can change the selected text
|
|
139
|
+
if (this.cachedSelection) {
|
|
140
|
+
this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
|
|
141
|
+
}
|
|
142
|
+
this.editor.format('color', this.selectedColor)
|
|
143
|
+
this.debouncedSanitizeAndValidate()
|
|
122
144
|
}
|
|
123
145
|
|
|
124
146
|
protected colorInputOpened() {
|
|
125
|
-
|
|
147
|
+
|
|
148
|
+
this.cachedSelection = this.editor.getSelection()
|
|
126
149
|
}
|
|
127
150
|
|
|
128
151
|
protected fontSelected(fontFamily: string): void {
|
|
@@ -130,141 +153,234 @@ export default class RichTextComponentController implements ng.IComponentControl
|
|
|
130
153
|
if (!fontFamily) { return }
|
|
131
154
|
|
|
132
155
|
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
156
|
this.editor.format('font', fontFamily)
|
|
138
157
|
|
|
139
|
-
this.
|
|
158
|
+
this.debouncedSanitizeAndValidate()
|
|
140
159
|
}
|
|
141
160
|
|
|
142
|
-
|
|
161
|
+
/** The user entered/deleted/modified some text. Handle any formatting issues, then store the model. */
|
|
162
|
+
protected onTextChange(delta: Delta, _oldContents: Delta, source: EmitterSource): void {
|
|
143
163
|
|
|
144
|
-
|
|
164
|
+
if (source !== 'user') { return }
|
|
165
|
+
|
|
166
|
+
this.$timeout(() => {
|
|
167
|
+
// Quill's "Clear formatting" button leaves us inheriting styles from the CSS. We want to keep things explicit.
|
|
168
|
+
this.fixClearFormatting(delta)
|
|
169
|
+
|
|
170
|
+
// Also, things like adding a line break can leave us with no style.
|
|
171
|
+
this.fixMissingFormats()
|
|
172
|
+
})
|
|
145
173
|
|
|
146
|
-
this.
|
|
174
|
+
this.debouncedSanitizeAndValidate()
|
|
147
175
|
}
|
|
148
176
|
|
|
149
|
-
|
|
177
|
+
/** The user moved the cursor. Fix missing formats and update the toolbar to reflect the current selection. */
|
|
178
|
+
protected selectionChange(range: Range, _oldRange: Range, source: EmitterSource): void {
|
|
150
179
|
|
|
151
180
|
if (source !== 'user') { return }
|
|
181
|
+
if (!range) { return }
|
|
152
182
|
|
|
153
|
-
|
|
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
|
|
162
|
-
}
|
|
183
|
+
this.fixMissingFormats()
|
|
163
184
|
|
|
164
|
-
this
|
|
185
|
+
this.$timeout(() => {
|
|
186
|
+
// Quill updates the toolbar to reflect most formatting (bold, italics, bullet points, etc.), but
|
|
187
|
+
// fonts, text size, and color are handled by plugins so we need to update those ourselves.
|
|
188
|
+
const format = this.editor.getFormat(range)
|
|
189
|
+
this.updateFontPicker(this.getFontFromFormat(format))
|
|
190
|
+
this.updateColorPicker(this.getColorFromFormat(format))
|
|
191
|
+
this.updateSizePicker(this.getSizeFromFormat(format))
|
|
192
|
+
})
|
|
193
|
+
}
|
|
165
194
|
|
|
166
|
-
|
|
167
|
-
if (!selection) { return }
|
|
195
|
+
private checkValidity(): void {
|
|
168
196
|
|
|
169
|
-
const
|
|
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()
|
|
174
|
-
}
|
|
175
|
-
}
|
|
197
|
+
const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
|
|
176
198
|
|
|
177
|
-
|
|
199
|
+
this.$timeout(() => {
|
|
200
|
+
this.ngModelCtrl.$setValidity('required', isValid)
|
|
201
|
+
})
|
|
202
|
+
}
|
|
178
203
|
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Quill's "Clear formatting" button leaves us with no font, size, or color, so the style is inherited from the CSS.
|
|
206
|
+
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
207
|
+
* reproduced elsewhere.
|
|
208
|
+
*/
|
|
209
|
+
private fixClearFormatting(delta: Delta): void {
|
|
210
|
+
|
|
211
|
+
// Using the "Clear formatting" button creates a delta that sets font, size, and color to `null`. Detect any of those.
|
|
212
|
+
// (Usually you'd get all three together, but some might be missing from the delta if they were already clear,
|
|
213
|
+
// for example if we were editing an old Workspace Text Section that was created using an older version of this component.)
|
|
214
|
+
if (delta.ops.some((op) => op.retain && (
|
|
215
|
+
op.attributes?.font === null || op.attributes?.size === null || op.attributes?.color === null
|
|
216
|
+
))) {
|
|
217
|
+
this.editor.format('font', this.DEFAULT_FONT)
|
|
218
|
+
this.updateFontPicker(this.DEFAULT_FONT)
|
|
219
|
+
this.editor.format('size', this.DEFAULT_SIZE)
|
|
220
|
+
this.updateSizePicker(this.DEFAULT_SIZE)
|
|
221
|
+
this.editor.format('color', this.DEFAULT_COLOR)
|
|
222
|
+
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
181
225
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Quill likes to default to no formatting: an empty paragraph has no font, size, or color, so the style is inherited
|
|
228
|
+
* from the CSS.
|
|
229
|
+
* We don't want that: we want everything to be fully defined, so that the user-entered text can be faithfully
|
|
230
|
+
* reproduced elsewhere.
|
|
231
|
+
* We try to get the format from the previous line, or fall back to the default.
|
|
232
|
+
*/
|
|
233
|
+
private fixMissingFormats(): void {
|
|
185
234
|
|
|
186
|
-
this
|
|
235
|
+
// When debugging this, it can be useful to add this to your CSS to highlight problems:
|
|
236
|
+
// .ql-editor { color: #f0f; font-family: 'Wingdings', sans-serif; font-size: 9px; }
|
|
187
237
|
|
|
188
|
-
|
|
189
|
-
if (!
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
$('#editorSize .ql-picker-label').attr('data-label',this.DEFAULT_SIZE)
|
|
238
|
+
const selection = this.editor.getSelection()
|
|
239
|
+
if (!selection || selection.length) {
|
|
240
|
+
// Some text is selected; we don't want to change this
|
|
241
|
+
return
|
|
193
242
|
}
|
|
194
243
|
|
|
195
|
-
|
|
196
|
-
|
|
244
|
+
const format = this.editor.getFormat()
|
|
245
|
+
if (format.font && format.size && format.color) {
|
|
246
|
+
// We are fully formatted; nothing more to do
|
|
197
247
|
return
|
|
198
248
|
}
|
|
199
249
|
|
|
250
|
+
// Copy missing format from the previous character (or the next, if we're at the start of the document)
|
|
251
|
+
const nearbyCharIndex = selection.index === 0 ? 1 : selection.index - 1
|
|
252
|
+
const nearbyRange: Range = {
|
|
253
|
+
index: nearbyCharIndex,
|
|
254
|
+
length: 0,
|
|
255
|
+
}
|
|
256
|
+
const nearbyFormat = this.editor.getFormat(nearbyRange)
|
|
257
|
+
|
|
258
|
+
this.editor.format('bold', nearbyFormat.bold)
|
|
259
|
+
this.editor.format('italic', nearbyFormat.italic)
|
|
260
|
+
this.editor.format('underline', nearbyFormat.underline)
|
|
261
|
+
|
|
200
262
|
if (!format.font) {
|
|
201
|
-
|
|
263
|
+
const font = this.getFontFromFormat(nearbyFormat)
|
|
264
|
+
this.editor.format('font', font)
|
|
265
|
+
this.updateFontPicker(font)
|
|
202
266
|
}
|
|
203
|
-
}
|
|
204
267
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.editor.setSelection(this.cachedSelection.index, this.cachedSelection.length)
|
|
268
|
+
if (!format.size) {
|
|
269
|
+
const size = this.getSizeFromFormat(nearbyFormat)
|
|
270
|
+
this.editor.format('size', size)
|
|
271
|
+
this.updateSizePicker(size)
|
|
210
272
|
}
|
|
211
|
-
this.editor.format('color', this.selectedColor)
|
|
212
|
-
this.sanitizeContents()
|
|
213
|
-
}
|
|
214
273
|
|
|
215
|
-
|
|
216
|
-
|
|
274
|
+
if (!format.color) {
|
|
275
|
+
const color = this.getColorFromFormat(nearbyFormat)
|
|
276
|
+
this.editor.format('color', color)
|
|
277
|
+
this.updateColorPicker(color)
|
|
278
|
+
}
|
|
217
279
|
}
|
|
218
280
|
|
|
219
|
-
private
|
|
281
|
+
private getColorFromFormat(format: QuillFormat): string {
|
|
220
282
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
283
|
+
if (!format.color) {
|
|
284
|
+
// We get no color if the default color is selected; or if the selection contains multiple colors, one of which is the default.
|
|
285
|
+
return this.DEFAULT_COLOR
|
|
286
|
+
}
|
|
225
287
|
|
|
226
|
-
|
|
288
|
+
if (typeof format.color === 'string') {
|
|
289
|
+
// The selected range is all the same color, which is not the default.
|
|
290
|
+
return format.color
|
|
291
|
+
}
|
|
227
292
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
293
|
+
if (Array.isArray(format.color)) {
|
|
294
|
+
// The selected range contains multiple colors, none of which are the default. Return the default, to be consistent with other multi-color selections.
|
|
295
|
+
return this.DEFAULT_COLOR
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Fall back to the default (should never get here)
|
|
299
|
+
return this.DEFAULT_COLOR
|
|
231
300
|
}
|
|
232
301
|
|
|
233
|
-
private
|
|
234
|
-
|
|
302
|
+
private getFontFromFormat(format: QuillFormat): string {
|
|
303
|
+
|
|
304
|
+
if (!format.font) {
|
|
305
|
+
// No font is defined for the selection, so show the default. This can happen if you're on a new empty line.
|
|
306
|
+
return this.DEFAULT_FONT
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (typeof format.font === 'string') {
|
|
310
|
+
// The range uses a single font.
|
|
311
|
+
return format.font
|
|
312
|
+
}
|
|
235
313
|
|
|
236
|
-
if (
|
|
314
|
+
if (Array.isArray(format.font)) {
|
|
315
|
+
// The selected range contains multiple fonts, so show blank.
|
|
316
|
+
return ''
|
|
317
|
+
}
|
|
237
318
|
|
|
238
|
-
|
|
319
|
+
// Fall back to the default (should never get here)
|
|
320
|
+
return this.DEFAULT_FONT
|
|
239
321
|
}
|
|
240
322
|
|
|
241
|
-
private
|
|
323
|
+
private getSizeFromFormat(format: QuillFormat): string {
|
|
324
|
+
|
|
325
|
+
if (!format.size) {
|
|
326
|
+
// We get no size if the default size is selected; or if the selection contains multiple sizes, one of which is the default.
|
|
327
|
+
return this.DEFAULT_SIZE
|
|
328
|
+
}
|
|
242
329
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
330
|
+
if (typeof format.size === 'string') {
|
|
331
|
+
// The selected range is all the same size, which is not the default.
|
|
332
|
+
return format.size
|
|
246
333
|
}
|
|
334
|
+
|
|
335
|
+
if (Array.isArray(format.size)) {
|
|
336
|
+
// The selected range contains multiple sizes, none of which are the default. Return the first size in the array.
|
|
337
|
+
return format.size[0]
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Fall back to the default (should never get here)
|
|
341
|
+
return this.DEFAULT_FONT
|
|
247
342
|
}
|
|
248
343
|
|
|
249
|
-
private
|
|
344
|
+
private sanitizeAndValidate(): void {
|
|
250
345
|
|
|
251
|
-
|
|
252
|
-
const format = this.editor.getFormat(range)
|
|
253
|
-
const color = format.color
|
|
346
|
+
let html: string | undefined
|
|
254
347
|
|
|
255
|
-
|
|
256
|
-
|
|
348
|
+
// An empty Quill editor's html might be like:
|
|
349
|
+
// <p><span style="font-family: Roboto; font-size: 14px; color: rgb(83, 83, 83);"><span class="ql-cursor"></span></span></p>
|
|
350
|
+
// Detect emptiness and return `undefined` instead, for easier "Required" validation.
|
|
351
|
+
if (!this.editor.getText().trim()) {
|
|
352
|
+
html = undefined
|
|
353
|
+
} else {
|
|
354
|
+
// Sometimes Quill's inner HTML includes its own cursor. We don't want to save that.
|
|
355
|
+
const withoutCursor = this.editor.root.innerHTML.replace(/\<span class="ql-cursor"\>.?\<\/span\>/, '')
|
|
356
|
+
html = this.$sanitize(withoutCursor)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this.ngModelCtrl.$setViewValue(html)
|
|
360
|
+
this.checkValidity()
|
|
361
|
+
}
|
|
257
362
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (_.isArray(color)) {
|
|
363
|
+
/** Updates the color shown in the toolbar. Does not change the color being used in the text. */
|
|
364
|
+
private updateColorPicker(color: string): void {
|
|
261
365
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
366
|
+
this.selectedColor = color
|
|
367
|
+
}
|
|
265
368
|
|
|
266
|
-
|
|
267
|
-
|
|
369
|
+
/** Updates the font shown in the toolbar. Does not change the font being used in the text. */
|
|
370
|
+
private updateFontPicker(font: string): void {
|
|
268
371
|
|
|
372
|
+
this.selectedFont = font
|
|
269
373
|
}
|
|
374
|
+
|
|
375
|
+
/** Updates the size shown in the toolbar. Does not change the size being used in the text. */
|
|
376
|
+
private updateSizePicker(size: string): void {
|
|
377
|
+
|
|
378
|
+
this.$element.find('.ql-size').val(size)
|
|
379
|
+
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-value', size)
|
|
380
|
+
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-label', size)
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
interface QuillFormat {
|
|
385
|
+
[format: string]: unknown
|
|
270
386
|
}
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1792,8 +1792,8 @@
|
|
|
1792
1792
|
"affectsGlobalScope": false
|
|
1793
1793
|
},
|
|
1794
1794
|
"./src/components/dropdown/dropdown.ts": {
|
|
1795
|
-
"version": "
|
|
1796
|
-
"signature": "
|
|
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": "
|
|
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/
|
|
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
|
|
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
|
|
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",
|