@mediafly/js-ui 50.2.1-2 → 50.2.1-3
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/.certs/ca.crt +33 -33
- package/.certs/localhost.crt +34 -33
- package/.certs/localhost.key +27 -28
- package/.certs/localhost.pfx +0 -0
- package/lib/dropdown/dropdown.js +2 -0
- package/lib/dropdown/dropdown.js.map +1 -1
- package/lib/font-selector/font-selector.js +1 -1
- package/lib/metadata-form/metadata-form.component.js +7 -0
- package/lib/metadata-form/metadata-form.component.js.map +1 -1
- package/lib/metadata-form/metadata-form.html +2 -0
- package/lib/rich-text/rich-text.component.d.ts +18 -50
- package/lib/rich-text/rich-text.component.html +3 -3
- package/lib/rich-text/rich-text.component.js +115 -283
- package/lib/rich-text/rich-text.component.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +8 -417
- package/package.json +2 -3
- package/src/components/dropdown/dropdown.ts +3 -1
- package/src/components/font-selector/font-selector.ts +1 -1
- package/src/components/less/vendor/quill.snow.css +941 -6
- package/src/components/metadata-form/metadata-form.component.ts +15 -7
- package/src/components/metadata-form/metadata-form.html +2 -0
- package/src/components/rich-text/rich-text.component.html +3 -3
- package/src/components/rich-text/rich-text.component.ts +127 -309
- package/tsconfig.tsbuildinfo +0 -7221
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
// tslint:disable: max-file-line-count
|
|
2
1
|
import angular, { sanitize } from 'angular'
|
|
3
2
|
import _ from 'lodash'
|
|
4
|
-
import Quill
|
|
5
|
-
import
|
|
3
|
+
import Quill from 'quill'
|
|
4
|
+
import $ from 'jquery'
|
|
5
|
+
import { FontFamilyStyle } from '../font-selector/font-selector'
|
|
6
6
|
import { Component, Inject, Input } from '../decorators'
|
|
7
|
-
import type { TranslateFactory } from '../translate/translate-factory'
|
|
8
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
9
7
|
|
|
10
8
|
// text editor requires sanitization but also needs to allow for style attributes which are removed by default
|
|
11
9
|
angular.module('app').config(['$sanitizeProvider', ($sanitizeProvider: ng.sanitize.ISanitizeProvider) => {
|
|
@@ -26,135 +24,105 @@ export default class RichTextComponentController implements ng.IComponentControl
|
|
|
26
24
|
@Input() allowFontSelection?: boolean
|
|
27
25
|
@Input() isRequired!: boolean
|
|
28
26
|
|
|
29
|
-
protected cachedSelection?:
|
|
30
|
-
protected
|
|
31
|
-
protected editorSizeId: string
|
|
27
|
+
protected cachedSelection?: { index: number; length: number; }
|
|
28
|
+
protected fontStyle?: FontFamilyStyle
|
|
32
29
|
protected fontSelectorId: string
|
|
33
30
|
protected requiredText: string
|
|
34
31
|
protected selectedColor: string
|
|
35
32
|
protected selectedFont: string
|
|
36
|
-
protected toolbarId: string
|
|
37
33
|
protected validationForm: ng.IFormController
|
|
38
34
|
|
|
39
|
-
private colorPicker
|
|
40
|
-
private editor
|
|
35
|
+
private colorPicker
|
|
36
|
+
private editor
|
|
41
37
|
private ngModelCtrl: ng.INgModelController
|
|
42
38
|
|
|
43
|
-
private
|
|
39
|
+
private debouncedOnTextChange = _.debounce((delta, oldContents, source) => this.onTextChange(delta, oldContents, source), 250)
|
|
44
40
|
|
|
45
41
|
private DEFAULT_COLOR = '#535353'
|
|
46
42
|
private DEFAULT_FONT = 'Roboto'
|
|
47
43
|
private DEFAULT_SIZE = '14px'
|
|
48
44
|
|
|
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 = '20px'
|
|
56
|
-
|
|
57
45
|
constructor(
|
|
58
46
|
@Inject('$element') private $element: ng.IAugmentedJQuery,
|
|
59
47
|
@Inject('$rootScope') private $rootScope: JSUIRootScope,
|
|
60
48
|
@Inject('$sanitize') private $sanitize: sanitize.ISanitizeService,
|
|
61
49
|
@Inject('$timeout') private $timeout: ng.ITimeoutService,
|
|
62
|
-
@Inject('translateFactory') private translateFactory
|
|
63
|
-
) {
|
|
50
|
+
@Inject('translateFactory') private translateFactory
|
|
51
|
+
) {}
|
|
64
52
|
|
|
65
53
|
$onChanges(changes: { isRequired?: ng.IChangesObject<boolean> }) {
|
|
66
|
-
|
|
67
54
|
if (!changes.isRequired) { return }
|
|
68
55
|
if (changes.isRequired.currentValue === changes.isRequired.previousValue) { return }
|
|
69
56
|
|
|
70
|
-
this.
|
|
57
|
+
this.manageValidity()
|
|
71
58
|
}
|
|
72
59
|
|
|
73
60
|
$onDestroy() {
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
this.colorPicker
|
|
77
|
-
this.colorPicker?.removeEventListener('click', this.colorInputOpened.bind(this))
|
|
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))
|
|
78
64
|
}
|
|
79
65
|
|
|
80
66
|
$onInit() {
|
|
81
|
-
|
|
82
67
|
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)
|
|
83
71
|
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
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))
|
|
72
|
+
this.colorPicker = document.getElementById('rteColorInput')
|
|
73
|
+
this.colorPicker.addEventListener('change', this.colorChanged.bind(this))
|
|
74
|
+
this.colorPicker.addEventListener('click', this.colorInputOpened.bind(this))
|
|
93
75
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.updateColorPicker(this.DEFAULT_COLOR)
|
|
97
|
-
})
|
|
76
|
+
// programatically reset size
|
|
77
|
+
$('.ql-size').val(this.DEFAULT_SIZE)
|
|
98
78
|
}
|
|
99
79
|
|
|
100
80
|
$postLink() {
|
|
101
81
|
|
|
102
|
-
Quill.register(Quill.import('attributors/class/background')
|
|
103
|
-
Quill.register(Quill.import('attributors/style/color')
|
|
82
|
+
Quill.register(Quill.import('attributors/class/background'), true)
|
|
83
|
+
Quill.register(Quill.import('attributors/style/color'), true)
|
|
104
84
|
|
|
105
|
-
const fontStyle = Quill.import('attributors/style/font')
|
|
106
|
-
|
|
107
|
-
fontStyle.whitelist = undefined
|
|
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)
|
|
108
87
|
Quill.register(fontStyle, true)
|
|
109
88
|
|
|
110
|
-
const fontSizeArr = ['10px',
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
Quill.register(
|
|
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)
|
|
114
93
|
|
|
115
94
|
const options = {
|
|
116
95
|
modules: {
|
|
117
|
-
toolbar:
|
|
96
|
+
toolbar: '#toolbar'
|
|
118
97
|
},
|
|
119
98
|
theme: 'snow',
|
|
120
99
|
}
|
|
121
100
|
|
|
122
|
-
this.$
|
|
123
|
-
this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
|
|
101
|
+
this.editor = new Quill(this.$element.find('.js-rich-text-target')[0], options)
|
|
124
102
|
|
|
125
|
-
|
|
126
|
-
|
|
103
|
+
// Disable spellcheck because of a bad bug that deletes text (CE-4692).
|
|
104
|
+
this.editor.root.setAttribute('spellcheck', false)
|
|
127
105
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
})
|
|
106
|
+
this.editor.on('text-change', this.debouncedOnTextChange)
|
|
107
|
+
this.editor.on('selection-change', this.selectionChange.bind(this))
|
|
131
108
|
|
|
132
109
|
this.ngModelCtrl.$render = () => {
|
|
133
|
-
this.$
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.editor.root.innerHTML = this.ngModelCtrl.$viewValue
|
|
140
|
-
})
|
|
110
|
+
if (!this.ngModelCtrl.$viewValue) {
|
|
111
|
+
this.editor.setText('\n')
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.editor.root.innerHTML = this.ngModelCtrl.$viewValue
|
|
141
116
|
}
|
|
117
|
+
|
|
142
118
|
}
|
|
143
119
|
|
|
144
120
|
protected colorChanged() {
|
|
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()
|
|
121
|
+
this.applyColor()
|
|
153
122
|
}
|
|
154
123
|
|
|
155
124
|
protected colorInputOpened() {
|
|
156
|
-
|
|
157
|
-
this.cachedSelection = this.editor.getSelection()
|
|
125
|
+
this.cacheSelection()
|
|
158
126
|
}
|
|
159
127
|
|
|
160
128
|
protected fontSelected(fontFamily: string): void {
|
|
@@ -162,291 +130,141 @@ export default class RichTextComponentController implements ng.IComponentControl
|
|
|
162
130
|
if (!fontFamily) { return }
|
|
163
131
|
|
|
164
132
|
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)
|
|
165
137
|
this.editor.format('font', fontFamily)
|
|
166
138
|
|
|
167
|
-
this.
|
|
139
|
+
this.sanitizeContents()
|
|
168
140
|
}
|
|
169
141
|
|
|
170
|
-
|
|
171
|
-
protected onTextChange(delta: Delta, _oldContents: Delta, source: EmitterSource): void {
|
|
142
|
+
protected manageValidity(): void {
|
|
172
143
|
|
|
173
|
-
|
|
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)
|
|
181
|
-
|
|
182
|
-
// Also, things like adding a line break can leave us with no style.
|
|
183
|
-
this.fixMissingFormats()
|
|
184
|
-
})
|
|
144
|
+
const isValid = !this.isRequired || !!this.ngModelCtrl.$viewValue
|
|
185
145
|
|
|
186
|
-
this.
|
|
146
|
+
this.ngModelCtrl.$setValidity('required', isValid)
|
|
187
147
|
}
|
|
188
148
|
|
|
189
|
-
|
|
190
|
-
protected selectionChange(range: Range, _oldRange: Range, source: EmitterSource): void {
|
|
149
|
+
protected onTextChange(_delta, _oldContents, source): void {
|
|
191
150
|
|
|
192
151
|
if (source !== 'user') { return }
|
|
193
|
-
if (!range) { return }
|
|
194
|
-
|
|
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
152
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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)
|
|
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
|
|
235
162
|
}
|
|
236
|
-
}
|
|
237
163
|
|
|
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 }
|
|
164
|
+
this.sanitizeContents()
|
|
248
165
|
|
|
249
166
|
const selection = this.editor.getSelection()
|
|
250
167
|
if (!selection) { return }
|
|
251
168
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
//
|
|
256
|
-
|
|
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]]
|
|
260
|
-
}
|
|
261
|
-
|
|
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
|
|
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()
|
|
278
174
|
}
|
|
175
|
+
}
|
|
279
176
|
|
|
280
|
-
|
|
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
|
-
}
|
|
177
|
+
protected selectionChange(range, oldRange, source): void {
|
|
286
178
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
this.updateColorPicker(color)
|
|
290
|
-
}
|
|
179
|
+
if (source !== 'user') { return }
|
|
180
|
+
if (!range) { return }
|
|
291
181
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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 {
|
|
182
|
+
const leaf = this.editor.getLeaf(range.index)
|
|
183
|
+
const font = this.getFontFromLeaf(leaf)
|
|
184
|
+
const format = this.editor.getFormat(range)
|
|
300
185
|
|
|
301
|
-
|
|
302
|
-
// .ql-editor { color: #f0f; font-family: 'Wingdings', sans-serif; font-size: 9px; }
|
|
186
|
+
this.updateColorDisplay(range)
|
|
303
187
|
|
|
304
|
-
|
|
305
|
-
if (!
|
|
306
|
-
|
|
307
|
-
|
|
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)
|
|
308
193
|
}
|
|
309
194
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// We are fully formatted; nothing more to do
|
|
195
|
+
if (font) {
|
|
196
|
+
this.updateFontDisplay(font.replace(/"/g, ''))
|
|
313
197
|
return
|
|
314
198
|
}
|
|
315
199
|
|
|
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
|
-
|
|
328
200
|
if (!format.font) {
|
|
329
|
-
|
|
330
|
-
this.editor.format('font', font)
|
|
331
|
-
this.updateFontPicker(font)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (!format.size) {
|
|
335
|
-
const size = this.getSizeFromFormat(nearbyFormat)
|
|
336
|
-
this.editor.format('size', size)
|
|
337
|
-
this.updateSizePicker(size)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (!format.color) {
|
|
341
|
-
const color = this.getColorFromFormat(nearbyFormat)
|
|
342
|
-
this.editor.format('color', color)
|
|
343
|
-
this.updateColorPicker(color)
|
|
201
|
+
this.editor.format('font', this.DEFAULT_FONT)
|
|
344
202
|
}
|
|
345
203
|
}
|
|
346
204
|
|
|
347
|
-
private
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
}
|
|
358
|
-
|
|
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
|
|
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)
|
|
362
210
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return this.DEFAULT_COLOR
|
|
211
|
+
this.editor.format('color', this.selectedColor)
|
|
212
|
+
this.sanitizeContents()
|
|
366
213
|
}
|
|
367
214
|
|
|
368
|
-
private
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
}
|
|
215
|
+
private cacheSelection(): void {
|
|
216
|
+
this.cachedSelection = this.editor.getSelection()
|
|
217
|
+
}
|
|
379
218
|
|
|
380
|
-
|
|
381
|
-
// The selected range contains multiple fonts, so show blank.
|
|
382
|
-
return ''
|
|
383
|
-
}
|
|
219
|
+
private sanitizeContents(): void {
|
|
384
220
|
|
|
385
|
-
|
|
386
|
-
|
|
221
|
+
const html = this.$sanitize(this.editor.root.innerHTML)
|
|
222
|
+
this.ngModelCtrl.$setViewValue(html)
|
|
223
|
+
this.manageValidity()
|
|
387
224
|
}
|
|
388
225
|
|
|
389
|
-
private
|
|
226
|
+
private formatToDefaults() {
|
|
390
227
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
228
|
+
this.updateFontDisplay(this.DEFAULT_FONT)
|
|
229
|
+
this.editor.format('color', this.DEFAULT_COLOR)
|
|
230
|
+
this.editor.format('size', this.DEFAULT_SIZE)
|
|
231
|
+
}
|
|
395
232
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return format.size
|
|
399
|
-
}
|
|
233
|
+
private getFontFromLeaf(leaf): string | undefined {
|
|
234
|
+
if (!leaf) { return }
|
|
400
235
|
|
|
401
|
-
if (
|
|
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]
|
|
404
|
-
}
|
|
236
|
+
if (!leaf[0].parent.domNode.style.fontFamily) { return }
|
|
405
237
|
|
|
406
|
-
|
|
407
|
-
return this.DEFAULT_FONT
|
|
238
|
+
return leaf[0].parent.domNode.style.fontFamily
|
|
408
239
|
}
|
|
409
240
|
|
|
410
|
-
private
|
|
411
|
-
|
|
412
|
-
let html: string | undefined
|
|
241
|
+
private updateFontDisplay(fontFamily: string): void {
|
|
413
242
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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)
|
|
243
|
+
this.selectedFont = fontFamily
|
|
244
|
+
this.fontStyle = {
|
|
245
|
+
'font-family': fontFamily
|
|
423
246
|
}
|
|
424
|
-
|
|
425
|
-
this.ngModelCtrl.$setViewValue(html)
|
|
426
|
-
this.checkValidity()
|
|
427
247
|
}
|
|
428
248
|
|
|
429
|
-
|
|
430
|
-
private updateColorPicker(color: string): void {
|
|
249
|
+
private updateColorDisplay(range: any): void {
|
|
431
250
|
|
|
432
|
-
this
|
|
433
|
-
|
|
251
|
+
this.$timeout(() => {
|
|
252
|
+
const format = this.editor.getFormat(range)
|
|
253
|
+
const color = format.color
|
|
434
254
|
|
|
435
|
-
|
|
436
|
-
|
|
255
|
+
if (!color || _.isEmpty(color)) {
|
|
256
|
+
this.selectedColor = this.DEFAULT_COLOR
|
|
437
257
|
|
|
438
|
-
|
|
439
|
-
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
if (_.isArray(color)) {
|
|
440
261
|
|
|
441
|
-
|
|
442
|
-
|
|
262
|
+
this.selectedColor = color[0]
|
|
263
|
+
return
|
|
264
|
+
}
|
|
443
265
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
this.$element.find(`#${this.editorSizeId} .ql-picker-label`).attr('data-label', size)
|
|
447
|
-
}
|
|
448
|
-
}
|
|
266
|
+
this.selectedColor = color
|
|
267
|
+
})
|
|
449
268
|
|
|
450
|
-
|
|
451
|
-
[format: string]: unknown
|
|
269
|
+
}
|
|
452
270
|
}
|