@mediafly/js-ui 53.0.1 → 53.1.0-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.
- package/.github/dependabot.yml +30 -0
- package/.node-version +1 -1
- package/.semaphore/semaphore.yml +9 -6
- package/lib/fonts.css +1 -1
- package/lib/src/components/actionable-empty-state/actionable-empty-state.js +8 -8
- package/lib/src/components/actionable-empty-state/actionable-empty-state.js.map +1 -1
- package/lib/src/components/auto-complete/auto-complete-match-renderer.component.d.ts +1 -1
- package/lib/src/components/auto-complete/auto-complete-match-renderer.component.js +14 -14
- package/lib/src/components/auto-complete/auto-complete-match-renderer.component.js.map +1 -1
- package/lib/src/components/auto-complete/auto-complete.component.js +12 -12
- package/lib/src/components/auto-complete/auto-complete.component.js.map +1 -1
- package/lib/src/components/auto-focus/auto-focus.service.js +3 -3
- package/lib/src/components/auto-focus/auto-focus.service.js.map +1 -1
- package/lib/src/components/color-utils/color-utils.service.js +2 -2
- package/lib/src/components/color-utils/color-utils.service.js.map +1 -1
- package/lib/src/components/date-time-zone-city-picker/date-time-zone-city-picker.js +9 -9
- package/lib/src/components/date-time-zone-city-picker/date-time-zone-city-picker.js.map +1 -1
- package/lib/src/components/date-time-zone-city-picker/time-zone-city-picker.js +6 -6
- package/lib/src/components/date-time-zone-city-picker/time-zone-city-picker.js.map +1 -1
- package/lib/src/components/date-time-zone-picker/datepicker.js +1 -1
- package/lib/src/components/date-time-zone-picker/datepicker.js.map +1 -1
- package/lib/src/components/dropdown/dropdown.d.ts +3 -3
- package/lib/src/components/dropdown/dropdown.js +11 -11
- package/lib/src/components/dropdown/dropdown.js.map +1 -1
- package/lib/src/components/dropdown-menu/dropdown-menu-action.component.d.ts +1 -0
- package/lib/src/components/dropdown-menu/dropdown-menu-action.component.js +9 -9
- package/lib/src/components/dropdown-menu/dropdown-menu-action.component.js.map +1 -1
- package/lib/src/components/dropdown-menu/dropdown-menu-contents.js +6 -6
- package/lib/src/components/dropdown-menu/dropdown-menu-contents.js.map +1 -1
- package/lib/src/components/dropdown-menu/dropdown-menu.js +9 -9
- package/lib/src/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/lib/src/components/feedback/clipboard.service.js +5 -5
- package/lib/src/components/feedback/clipboard.service.js.map +1 -1
- package/lib/src/components/feedback/feedback.component.d.ts +1 -1
- package/lib/src/components/feedback/feedback.component.js +6 -6
- package/lib/src/components/feedback/feedback.component.js.map +1 -1
- package/lib/src/components/feedback/feedback.service.js +3 -3
- package/lib/src/components/feedback/feedback.service.js.map +1 -1
- package/lib/src/components/first-time-motivator/first-time-motivator.js +8 -8
- package/lib/src/components/first-time-motivator/first-time-motivator.js.map +1 -1
- package/lib/src/components/first-time-motivator/ftm-target-element.js +1 -1
- package/lib/src/components/first-time-motivator/ftm-target-element.js.map +1 -1
- package/lib/src/components/font-selector/font-selector.js +13 -13
- package/lib/src/components/font-selector/font-selector.js.map +1 -1
- package/lib/src/components/font-selector/google-webfonts-api.service.js +4 -4
- package/lib/src/components/font-selector/google-webfonts-api.service.js.map +1 -1
- package/lib/src/components/font-selector/webfont-loader.service.js +1 -1
- package/lib/src/components/font-selector/webfont-loader.service.js.map +1 -1
- package/lib/src/components/font-weight-selector/font-weight-selector.js +11 -11
- package/lib/src/components/font-weight-selector/font-weight-selector.js.map +1 -1
- package/lib/src/components/full-screen/full-screen.service.d.ts +1 -1
- package/lib/src/components/full-screen/full-screen.service.js +1 -1
- package/lib/src/components/full-screen/full-screen.service.js.map +1 -1
- package/lib/src/components/hover-tooltip/hover-tooltip.js +1 -1
- package/lib/src/components/hover-tooltip/hover-tooltip.js.map +1 -1
- package/lib/src/components/icon/icon.service.js +1 -1
- package/lib/src/components/icon/icon.service.js.map +1 -1
- package/lib/src/components/inline-text-input/inline-text-input.component.js +2 -2
- package/lib/src/components/inline-text-input/inline-text-input.component.js.map +1 -1
- package/lib/src/components/loading-indicator/loading-indicator.component.js +2 -2
- package/lib/src/components/loading-indicator/loading-indicator.component.js.map +1 -1
- package/lib/src/components/metadata-form/metadata-form.component.js +11 -11
- package/lib/src/components/metadata-form/metadata-form.component.js.map +1 -1
- package/lib/src/components/modal/modal.component.js +14 -14
- package/lib/src/components/modal/modal.component.js.map +1 -1
- package/lib/src/components/modal/modal.service.d.ts +2 -1
- package/lib/src/components/modal/modal.service.js +6 -6
- package/lib/src/components/modal/modal.service.js.map +1 -1
- package/lib/src/components/progress-bar/progress-bar.component.js +2 -2
- package/lib/src/components/progress-bar/progress-bar.component.js.map +1 -1
- package/lib/src/components/progress-circle/progress-circle.js +2 -2
- package/lib/src/components/progress-circle/progress-circle.js.map +1 -1
- package/lib/src/components/response-handlers/api-success-handlers.js +1 -1
- package/lib/src/components/response-handlers/api-success-handlers.js.map +1 -1
- package/lib/src/components/response-handlers/error-response.service.js +2 -2
- package/lib/src/components/response-handlers/error-response.service.js.map +1 -1
- package/lib/src/components/response-handlers/feedback-error-handler.js +4 -4
- package/lib/src/components/response-handlers/feedback-error-handler.js.map +1 -1
- package/lib/src/components/response-handlers/log-error-handler.js +2 -2
- package/lib/src/components/response-handlers/log-error-handler.js.map +1 -1
- package/lib/src/components/rich-text/rich-text.component.d.ts +8 -0
- package/lib/src/components/rich-text/rich-text.component.js +56 -19
- package/lib/src/components/rich-text/rich-text.component.js.map +1 -1
- package/lib/src/components/rich-text/rich-text.service.d.ts +24 -0
- package/lib/src/components/rich-text/rich-text.service.js +111 -2
- package/lib/src/components/rich-text/rich-text.service.js.map +1 -1
- package/lib/src/components/site-header/site-header-navbar-item.component.js +8 -8
- package/lib/src/components/site-header/site-header-navbar-item.component.js.map +1 -1
- package/lib/src/components/site-header/site-header.component.js +8 -8
- package/lib/src/components/site-header/site-header.component.js.map +1 -1
- package/lib/src/components/tabs/tab-group.js +3 -3
- package/lib/src/components/tabs/tab-group.js.map +1 -1
- package/lib/src/components/tabs/tab-html-title.js +2 -2
- package/lib/src/components/tabs/tab-html-title.js.map +1 -1
- package/lib/src/components/tabs/tab.js +8 -8
- package/lib/src/components/tabs/tab.js.map +1 -1
- package/lib/src/components/tag-input/tag-input.component.d.ts +1 -1
- package/lib/src/components/tag-input/tag-input.component.js +12 -12
- package/lib/src/components/tag-input/tag-input.component.js.map +1 -1
- package/lib/src/components/theme/theme.service.js +1 -1
- package/lib/src/components/theme/theme.service.js.map +1 -1
- package/lib/src/components/theme/theme.typings.d.ts +1 -1
- package/lib/src/components/type-string/type-string.component.js +3 -3
- package/lib/src/components/type-string/type-string.component.js.map +1 -1
- package/lib/src/components/url-modification/url-modification.service.js +1 -1
- package/lib/src/components/url-modification/url-modification.service.js.map +1 -1
- package/lib/styles.css +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +1 -6298
- package/package.json +60 -52
- package/src/components/rich-text/rich-text.component.less +10 -0
- package/src/components/rich-text/rich-text.component.ts +41 -1
- package/src/components/rich-text/rich-text.service.ts +471 -336
- package/src/index.spec.js +41 -40
- package/tsconfig.tsbuildinfo +1 -10494
- package/webpack.config.js +1 -1
|
@@ -1,336 +1,471 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
html
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
html =
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
1
|
+
// tslint:disable: max-file-line-count
|
|
2
|
+
import angular, { sanitize } from 'angular'
|
|
3
|
+
import { Inject, Injectable } from '../decorators'
|
|
4
|
+
|
|
5
|
+
// text editor requires sanitization but also needs to allow for style attributes which are removed by default
|
|
6
|
+
angular.module('app').config(['$sanitizeProvider', ($sanitizeProvider: ng.sanitize.ISanitizeProvider) => {
|
|
7
|
+
$sanitizeProvider.addValidAttrs(['style'])
|
|
8
|
+
|
|
9
|
+
// Quill uses data-list to distinguish bulleted lists from numbered lists (they are both provided as <ol>)
|
|
10
|
+
$sanitizeProvider.addValidAttrs(['data-list'])
|
|
11
|
+
|
|
12
|
+
// Allow target attribute on anchor tags
|
|
13
|
+
$sanitizeProvider.addValidAttrs(['target'])
|
|
14
|
+
}])
|
|
15
|
+
|
|
16
|
+
/** The text styles a list item's bullet or number copies from the item's first character. */
|
|
17
|
+
export const LIST_MARKER_PROPERTIES = ['color', 'font-family', 'font-size', 'font-weight'] as const
|
|
18
|
+
|
|
19
|
+
/** In the editor, marker styles go on the <li> as CSS variables, because Quill would read real ones as content formats. */
|
|
20
|
+
export const LIST_MARKER_VARIABLE_PREFIX = '--mfly-list-marker-'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Styles removed from list items before editing. As well as the marker styles, this includes the shared `padding-left`
|
|
24
|
+
* that js-ui 53.1.0-0 saved, which would otherwise override the em-based indent.
|
|
25
|
+
*/
|
|
26
|
+
const LIST_ITEM_STYLES_TO_CLEAR = [...LIST_MARKER_PROPERTIES, 'padding-left']
|
|
27
|
+
|
|
28
|
+
const LIST_ITEM_TAG_REGEX = /<li[\s>]/i
|
|
29
|
+
|
|
30
|
+
export type ListMarkerStyle = Partial<Record<typeof LIST_MARKER_PROPERTIES[number], string>>
|
|
31
|
+
|
|
32
|
+
@Injectable('richTextService')
|
|
33
|
+
export default class RichTextService {
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
@Inject('$sanitize') private $sanitize: sanitize.ISanitizeService,
|
|
37
|
+
) { }
|
|
38
|
+
|
|
39
|
+
/** Older versions of Quill rendered some things differently. Patch those up. */
|
|
40
|
+
backwardsCompatibleHtml(html: string): string {
|
|
41
|
+
|
|
42
|
+
html = this.removeZeroWidthNoBreakSpaces(html)
|
|
43
|
+
html = this.removeCursor(html)
|
|
44
|
+
html = this.fixWrappingCursor(html)
|
|
45
|
+
html = this.fixFontTags(html)
|
|
46
|
+
html = this.fixBulletPoints(html)
|
|
47
|
+
html = this.fixStrongBold(html)
|
|
48
|
+
html = this.removeListMarkerStyles(html)
|
|
49
|
+
|
|
50
|
+
return html
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Transform <ul><li> into <ol><li data-list="bullet">,
|
|
55
|
+
* and <ol><li> into <ol><li data-list="ordered">
|
|
56
|
+
* accounting for any pattern of nested <ul> and <ol> tags.
|
|
57
|
+
*/
|
|
58
|
+
fixBulletPoints(html: string): string {
|
|
59
|
+
|
|
60
|
+
if (!html) {
|
|
61
|
+
return html
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let newHtml: string = ''
|
|
65
|
+
|
|
66
|
+
// Regexes for these, in case someone invents a <link> tag or something
|
|
67
|
+
const olStartTagRegex = new RegExp(`<ol(\\s|>)`)
|
|
68
|
+
const ulStartTagRegex = new RegExp(`<ul(\\s|>)`)
|
|
69
|
+
const liStartTagRegex = new RegExp(`<li(\\s|>)`)
|
|
70
|
+
// Literal string matches for these
|
|
71
|
+
const olEndTag = `</ol>`
|
|
72
|
+
const ulEndTag = `</ul>`
|
|
73
|
+
|
|
74
|
+
// Stack of <ol> and <ul> tags, representing how the lists are nested
|
|
75
|
+
const listStack: string[] = []
|
|
76
|
+
|
|
77
|
+
let parsedLength = 0
|
|
78
|
+
let currentListType: string | undefined
|
|
79
|
+
|
|
80
|
+
// Loop through the input html, looking for <ol>, <ul> and <li> tags. Maintain a stack of nested lists, so
|
|
81
|
+
// we can transform the current <li> correctly.
|
|
82
|
+
while (parsedLength < html.length) {
|
|
83
|
+
|
|
84
|
+
// Find the start of the next <ol>, <ul> or <li> tag
|
|
85
|
+
const olStart = this.indexOfRegex(html, olStartTagRegex, parsedLength)
|
|
86
|
+
const ulStart = this.indexOfRegex(html, ulStartTagRegex, parsedLength)
|
|
87
|
+
const liStart = this.indexOfRegex(html, liStartTagRegex, parsedLength)
|
|
88
|
+
|
|
89
|
+
// Find what might be the end of the current list (or might be the end of a nested list)
|
|
90
|
+
let nextListEnd: number
|
|
91
|
+
switch (currentListType) {
|
|
92
|
+
case 'ol':
|
|
93
|
+
nextListEnd = html.indexOf(olEndTag, parsedLength)
|
|
94
|
+
break
|
|
95
|
+
case 'ul':
|
|
96
|
+
nextListEnd = html.indexOf(ulEndTag, parsedLength)
|
|
97
|
+
break
|
|
98
|
+
default:
|
|
99
|
+
nextListEnd = -1
|
|
100
|
+
break
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Find which tag comes next
|
|
104
|
+
const nextItemPos = Math.min(
|
|
105
|
+
olStart === -1 ? html.length : olStart,
|
|
106
|
+
ulStart === -1 ? html.length : ulStart,
|
|
107
|
+
liStart === -1 ? html.length : liStart,
|
|
108
|
+
nextListEnd === -1 ? html.length : nextListEnd)
|
|
109
|
+
|
|
110
|
+
newHtml += html.substring(parsedLength, nextItemPos)
|
|
111
|
+
parsedLength = nextItemPos
|
|
112
|
+
|
|
113
|
+
switch (nextItemPos) {
|
|
114
|
+
case olStart:
|
|
115
|
+
case ulStart:
|
|
116
|
+
// We've found the start of a list
|
|
117
|
+
newHtml += `<ol>`
|
|
118
|
+
|
|
119
|
+
const listTagEnd = html.indexOf('>', nextItemPos)
|
|
120
|
+
if (listTagEnd === -1) {
|
|
121
|
+
// Invalid HTML. Dump the lot.
|
|
122
|
+
return ''
|
|
123
|
+
}
|
|
124
|
+
parsedLength = listTagEnd + 1
|
|
125
|
+
|
|
126
|
+
if (nextItemPos === olStart) {
|
|
127
|
+
listStack.push('ol')
|
|
128
|
+
currentListType = 'ol'
|
|
129
|
+
} else {
|
|
130
|
+
listStack.push('ul')
|
|
131
|
+
currentListType = 'ul'
|
|
132
|
+
}
|
|
133
|
+
break
|
|
134
|
+
|
|
135
|
+
case liStart:
|
|
136
|
+
// We've found a list item
|
|
137
|
+
if (!currentListType) {
|
|
138
|
+
// Invalid HTML. Dump the lot.
|
|
139
|
+
return ''
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const liTagEnd = html.indexOf('>', liStart + 1)
|
|
143
|
+
if (liTagEnd === -1) {
|
|
144
|
+
// Invalid HTML. Dump the lot.
|
|
145
|
+
return ''
|
|
146
|
+
}
|
|
147
|
+
let liTag = html.substring(liStart, liTagEnd + 1)
|
|
148
|
+
|
|
149
|
+
if (liTag.indexOf('data-list') === -1) {
|
|
150
|
+
const dataAttr = ` data-list="${currentListType === 'ol' ? 'ordered' : 'bullet'}"`
|
|
151
|
+
liTag = `<li${dataAttr}` + liTag.substring(3)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
newHtml += liTag
|
|
155
|
+
parsedLength = liTagEnd + 1
|
|
156
|
+
break
|
|
157
|
+
|
|
158
|
+
case nextListEnd:
|
|
159
|
+
// We've reached the end of the current list. Write out the closing tag and pop the stack
|
|
160
|
+
newHtml += olEndTag
|
|
161
|
+
parsedLength = nextListEnd + olEndTag.length
|
|
162
|
+
listStack.pop()
|
|
163
|
+
currentListType = listStack[listStack.length - 1]
|
|
164
|
+
break
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (listStack.length > 0) {
|
|
169
|
+
// We didn't close the last list. Invalid HTML. Dump the lot.
|
|
170
|
+
return ''
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return newHtml
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Transform <font> tags from the old Quill editor into <span> tags, as used by the new editor.
|
|
178
|
+
* Quill used to set fonts using <font color="#000000" face="Open Sans">
|
|
179
|
+
* Now it uses <span style="font-family: "Open Sans"; color: rgb(0, 0, 0);">
|
|
180
|
+
* Although the former still renders correctly, it is skipped for editor.getText(), so it might report that the text editor is empty.
|
|
181
|
+
*/
|
|
182
|
+
fixFontTags(html: string): string {
|
|
183
|
+
|
|
184
|
+
if (!html) {
|
|
185
|
+
return html
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let fontTagPos = html.indexOf('<font')
|
|
189
|
+
while (fontTagPos > -1) {
|
|
190
|
+
const fontTagLength = html.indexOf('>', fontTagPos) - fontTagPos + 1
|
|
191
|
+
const fontTag = html.substr(fontTagPos, fontTagLength)
|
|
192
|
+
|
|
193
|
+
const faceMatch = fontTag.match(/face="([^"]+)"/)
|
|
194
|
+
const colorMatch = fontTag.match(/color="([^"]+)"/)
|
|
195
|
+
|
|
196
|
+
const styles: string[] = []
|
|
197
|
+
if (faceMatch) {
|
|
198
|
+
styles.push(`font-family: "${faceMatch[1]}";`)
|
|
199
|
+
}
|
|
200
|
+
if (colorMatch) {
|
|
201
|
+
styles.push(`color: ${colorMatch[1]};`)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
html =
|
|
205
|
+
html.substr(0, fontTagPos) +
|
|
206
|
+
`<span style="${styles.join(' ')}">` +
|
|
207
|
+
html.substr(fontTagPos + fontTagLength)
|
|
208
|
+
|
|
209
|
+
fontTagPos = html.indexOf('<font')
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
html = html.replace(/<\/font>/g, '<\/span>')
|
|
213
|
+
|
|
214
|
+
return html
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Quill adds its own editor cursor to its HTML: <span class="ql-cursor">|</span>
|
|
219
|
+
* These days we remove that on save, but sometimes it's present in the HTML that was saved by an older version of the editor.
|
|
220
|
+
* In rare cases, the HTML wraps that span around actual content. This function fixes that.
|
|
221
|
+
*/
|
|
222
|
+
fixWrappingCursor(html: string): string {
|
|
223
|
+
|
|
224
|
+
if (!html) {
|
|
225
|
+
return html
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Regexes can't save us because the cursor span may contain other spans, like this:
|
|
229
|
+
// <p><span class="ql-cursor"><span style="font-size: 24px;">Yikes!</span></span></p>
|
|
230
|
+
// We want to remove the outer span, while preserving the inner span.
|
|
231
|
+
const cursorStartTag = `<span class="ql-cursor">`
|
|
232
|
+
const spanStartTag = `<span`
|
|
233
|
+
const spanEndTag = `</span>`
|
|
234
|
+
let cursorStart = html.indexOf(cursorStartTag)
|
|
235
|
+
while (cursorStart > -1) {
|
|
236
|
+
|
|
237
|
+
let currentPos = cursorStart
|
|
238
|
+
let spanDepth = 1
|
|
239
|
+
while (spanDepth > 0) {
|
|
240
|
+
const nextSpanStart = html.indexOf(spanStartTag, currentPos + 1)
|
|
241
|
+
const nextSpanEnd = html.indexOf(spanEndTag, currentPos + 1)
|
|
242
|
+
if (nextSpanStart === -1 && nextSpanEnd === -1) {
|
|
243
|
+
// Spans aren't closed properly, so we have invalid html. Dump the lot. (Should never happen.)
|
|
244
|
+
html = ''
|
|
245
|
+
spanDepth = 0
|
|
246
|
+
} else if (nextSpanStart > -1 && nextSpanStart < nextSpanEnd) {
|
|
247
|
+
// We've found another nested span
|
|
248
|
+
spanDepth++
|
|
249
|
+
currentPos = nextSpanStart
|
|
250
|
+
} else {
|
|
251
|
+
// We've found the end of our current span
|
|
252
|
+
spanDepth--
|
|
253
|
+
currentPos = nextSpanEnd
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (html !== '') {
|
|
258
|
+
const cursorEnd = currentPos + spanEndTag.length - 1
|
|
259
|
+
const cursorOuterLength = cursorEnd - cursorStart + 1
|
|
260
|
+
const cursorInnerLength = cursorOuterLength - cursorStartTag.length - spanEndTag.length
|
|
261
|
+
html =
|
|
262
|
+
html.substr(0, cursorStart) + // Everything before the cursor
|
|
263
|
+
html.substr(cursorStart + cursorStartTag.length, cursorInnerLength) + // Everything inside the cursor
|
|
264
|
+
html.substr(cursorEnd + 1) // Everything after the cursor
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// There might be multiple cursors - even nested cursors - so keep going until there are none left
|
|
268
|
+
cursorStart = html.indexOf(`<span class="ql-cursor">`)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return html
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* To transition to supporting Google font weights, we switched to inline font weights rather than quill's default <strong> tags.
|
|
276
|
+
* Replace the legacy strong's with regular span's and an inline font weight.
|
|
277
|
+
*/
|
|
278
|
+
fixStrongBold(html: string): string {
|
|
279
|
+
|
|
280
|
+
if (!html) { return html }
|
|
281
|
+
|
|
282
|
+
const bold = '700'
|
|
283
|
+
|
|
284
|
+
// Replace <strong> tags with <span> tags and add font-weight: 700
|
|
285
|
+
html = html.replace(/<strong([^>]*)>/g, (match, attributes) => {
|
|
286
|
+
// Check if there's already a style attribute
|
|
287
|
+
const styleMatch = attributes.match(/style="([^"]*)"/)
|
|
288
|
+
|
|
289
|
+
if (styleMatch) {
|
|
290
|
+
// There's already a style attribute, add font-weight to it
|
|
291
|
+
const existingStyles = (styleMatch[1] || '').trim()
|
|
292
|
+
|
|
293
|
+
// Check if font-weight is already present
|
|
294
|
+
if (existingStyles.includes('font-weight')) {
|
|
295
|
+
// Ignore existing font-weight
|
|
296
|
+
return `<span${attributes.replace(styleMatch[0], `style="${existingStyles}"`)}>`
|
|
297
|
+
} else {
|
|
298
|
+
// Add font-weight to styles
|
|
299
|
+
const separator = existingStyles.endsWith(';') ? ' ' : '; '
|
|
300
|
+
return `<span${attributes.replace(styleMatch[0], `style="${existingStyles}${separator}font-weight: ${bold};"`)}>`
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
// No style attribute exists, add one with font-weight
|
|
304
|
+
return `<span${attributes} style="font-weight: ${bold};">`
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
// Replace closing tags
|
|
309
|
+
html = html.replace(/<\/strong>/g, '</span>')
|
|
310
|
+
|
|
311
|
+
return html
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Helper method because regexes can't natively start searching from a given index */
|
|
315
|
+
indexOfRegex(text: string, regex: RegExp, fromIndex: number): number {
|
|
316
|
+
|
|
317
|
+
const match = text.substring(fromIndex).match(regex)
|
|
318
|
+
if (!match || match.index === undefined || match.index === -1) {
|
|
319
|
+
return -1
|
|
320
|
+
}
|
|
321
|
+
return fromIndex + match.index
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
|
|
325
|
+
removeCursor(html: string): string {
|
|
326
|
+
|
|
327
|
+
if (!html) {
|
|
328
|
+
return html
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return html.replace(/\<span class="ql-cursor"\>.?\<\/span\>/g, '')
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Sometimes Quill adds Zero Width No-Break Spaces. */
|
|
335
|
+
removeZeroWidthNoBreakSpaces(html: string): string {
|
|
336
|
+
|
|
337
|
+
if (!html) {
|
|
338
|
+
return html
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return html.replace(//g, '')
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Clean up the HTML, ready for save */
|
|
345
|
+
sanitizeHtml(html: string): string {
|
|
346
|
+
|
|
347
|
+
html = this.removeZeroWidthNoBreakSpaces(html)
|
|
348
|
+
html = this.removeCursor(html)
|
|
349
|
+
html = this.addListMarkerStyles(html)
|
|
350
|
+
html = this.$sanitize(html)
|
|
351
|
+
|
|
352
|
+
return html
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Quill only styles the text runs inside a list item, so a bullet or number would take the container's style,
|
|
357
|
+
* not its text's. Put the style of each item's first character on the <li> itself, so its marker inherits it.
|
|
358
|
+
* The item's em-based indent then also scales with its own marker.
|
|
359
|
+
* These styles are derived from the text, so `removeListMarkerStyles` can drop them again before editing.
|
|
360
|
+
*/
|
|
361
|
+
addListMarkerStyles(html: string): string {
|
|
362
|
+
|
|
363
|
+
if (!html || !LIST_ITEM_TAG_REGEX.test(html)) {
|
|
364
|
+
return html
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const template = document.createElement('template')
|
|
368
|
+
template.innerHTML = html
|
|
369
|
+
|
|
370
|
+
template.content.querySelectorAll('li').forEach((item) => {
|
|
371
|
+
const style = this.getListItemMarkerStyle(item)
|
|
372
|
+
this.clearListMarkerStyles(item)
|
|
373
|
+
|
|
374
|
+
for (const property of LIST_MARKER_PROPERTIES) {
|
|
375
|
+
const value = style?.[property]
|
|
376
|
+
if (value) {
|
|
377
|
+
item.style.setProperty(property, value)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!item.getAttribute('style')) {
|
|
382
|
+
item.removeAttribute('style')
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
return template.innerHTML
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Remove the list item styles added by `addListMarkerStyles` (and the editor's own marker variables), so Quill
|
|
391
|
+
* never reads font styles on a block. Only the <li> start tags are rewritten; the rest of the HTML is untouched.
|
|
392
|
+
*/
|
|
393
|
+
removeListMarkerStyles(html: string): string {
|
|
394
|
+
|
|
395
|
+
if (!html || !LIST_ITEM_TAG_REGEX.test(html)) {
|
|
396
|
+
return html
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return html.replace(/<li\b[^>]*\bstyle=[^>]*>/gi, (tag) => {
|
|
400
|
+
const template = document.createElement('template')
|
|
401
|
+
template.innerHTML = `<ol>${tag}</li></ol>`
|
|
402
|
+
|
|
403
|
+
const item = template.content.querySelector('li')
|
|
404
|
+
if (!item) {
|
|
405
|
+
return tag
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
this.clearListMarkerStyles(item)
|
|
409
|
+
if (!item.getAttribute('style')) {
|
|
410
|
+
item.removeAttribute('style')
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return item.outerHTML.slice(0, -'</li>'.length)
|
|
414
|
+
})
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The styles of a list item's first character, which its bullet or number should copy.
|
|
419
|
+
* Undefined when the item has no text yet.
|
|
420
|
+
*/
|
|
421
|
+
getListItemMarkerStyle(item: Element): ListMarkerStyle | undefined {
|
|
422
|
+
|
|
423
|
+
const firstText = this.findFirstText(item)
|
|
424
|
+
if (!firstText) {
|
|
425
|
+
return undefined
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const style: ListMarkerStyle = {}
|
|
429
|
+
for (const property of LIST_MARKER_PROPERTIES) {
|
|
430
|
+
for (let element = firstText.parentElement; element && element !== item; element = element.parentElement) {
|
|
431
|
+
const value = element.style?.getPropertyValue(property)
|
|
432
|
+
if (value) {
|
|
433
|
+
style[property] = value
|
|
434
|
+
break
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return style
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private findFirstText(item: Element): Text | undefined {
|
|
443
|
+
|
|
444
|
+
const walker = item.ownerDocument.createTreeWalker(item, NodeFilter.SHOW_TEXT)
|
|
445
|
+
|
|
446
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
447
|
+
// Skip Quill's marker element, and whitespace between tags
|
|
448
|
+
if (node.parentElement?.closest('.ql-ui')) {
|
|
449
|
+
continue
|
|
450
|
+
}
|
|
451
|
+
if (node.textContent?.replace(//g, '').trim()) {
|
|
452
|
+
return node as Text
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return undefined
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private clearListMarkerStyles(item: HTMLElement): void {
|
|
460
|
+
|
|
461
|
+
for (const property of Array.from(item.style)) {
|
|
462
|
+
if (property.startsWith(LIST_MARKER_VARIABLE_PREFIX)) {
|
|
463
|
+
item.style.removeProperty(property)
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
for (const property of LIST_ITEM_STYLES_TO_CLEAR) {
|
|
467
|
+
item.style.removeProperty(property)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
}
|