@mediafly/js-ui 51.2.2-0 → 51.2.2-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.
|
@@ -24,6 +24,8 @@ export default class RichTextService {
|
|
|
24
24
|
* In rare cases, the HTML wraps that span around actual content. This function fixes that.
|
|
25
25
|
*/
|
|
26
26
|
fixWrappingCursor(html: string): string;
|
|
27
|
+
/** Helper method because regexes can't natively start searching from a given index */
|
|
28
|
+
indexOfRegex(text: string, regex: RegExp, fromIndex: number): number;
|
|
27
29
|
/** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
|
|
28
30
|
removeCursor(html: string): string;
|
|
29
31
|
/** Sometimes Quill adds Zero Width No-Break Spaces. */
|
|
@@ -29,15 +29,10 @@ let RichTextService = class RichTextService {
|
|
|
29
29
|
}
|
|
30
30
|
/** Older versions of Quill rendered some things differently. Patch those up. */
|
|
31
31
|
backwardsCompatibleHtml(html) {
|
|
32
|
-
console.log(`-----> backwardsCompatibleHtml (${html.length}) ${html}`);
|
|
33
32
|
html = this.removeZeroWidthNoBreakSpaces(html);
|
|
34
|
-
console.log(`-----> after removeZeroWidthNoBreakSpaces (${html.length}) ${html}`);
|
|
35
33
|
html = this.removeCursor(html);
|
|
36
|
-
console.log(`-----> after removeCursor (${html.length}) ${html}`);
|
|
37
34
|
html = this.fixWrappingCursor(html);
|
|
38
|
-
console.log(`-----> after fixWrappingCursor (${html.length}) ${html}`);
|
|
39
35
|
html = this.fixFontTags(html);
|
|
40
|
-
console.log(`-----> after fixFontTags (${html.length}) ${html}`);
|
|
41
36
|
html = this.fixBulletPoints(html);
|
|
42
37
|
return html;
|
|
43
38
|
}
|
|
@@ -47,25 +42,28 @@ let RichTextService = class RichTextService {
|
|
|
47
42
|
* accounting for any pattern of nested <ul> and <ol> tags.
|
|
48
43
|
*/
|
|
49
44
|
fixBulletPoints(html) {
|
|
50
|
-
console.log(`-----> fixBulletPoints`, html);
|
|
51
45
|
if (!html) {
|
|
52
46
|
return html;
|
|
53
47
|
}
|
|
54
48
|
let newHtml = '';
|
|
55
|
-
|
|
49
|
+
// Regexes for these, in case someone invents a <link> tag or something
|
|
50
|
+
const olStartTagRegex = new RegExp(`<ol( |>)`);
|
|
51
|
+
const ulStartTagRegex = new RegExp(`<ul( |>)`);
|
|
52
|
+
const liStartTagRegex = new RegExp(`<li( |>)`);
|
|
53
|
+
// Literal string matches for these
|
|
56
54
|
const olEndTag = `</ol>`;
|
|
57
|
-
const ulStartTag = `<ul`;
|
|
58
55
|
const ulEndTag = `</ul>`;
|
|
59
|
-
|
|
60
|
-
const listStack = [];
|
|
56
|
+
// Stack of <ol> and <ul> tags, representing how the lists are nested
|
|
57
|
+
const listStack = [];
|
|
61
58
|
let parsedLength = 0;
|
|
62
59
|
let currentListType;
|
|
60
|
+
// Loop through the input html, looking for <ol>, <ul> and <li> tags. Maintain a stack of nested lists, so
|
|
61
|
+
// we can transform the current <li> correctly.
|
|
63
62
|
while (parsedLength < html.length) {
|
|
64
|
-
console.log(`-----> parsedLength ${parsedLength}`);
|
|
65
63
|
// Find the start of the next <ol>, <ul> or <li> tag
|
|
66
|
-
const olStart =
|
|
67
|
-
const ulStart =
|
|
68
|
-
const liStart =
|
|
64
|
+
const olStart = this.indexOfRegex(html, olStartTagRegex, parsedLength);
|
|
65
|
+
const ulStart = this.indexOfRegex(html, ulStartTagRegex, parsedLength);
|
|
66
|
+
const liStart = this.indexOfRegex(html, liStartTagRegex, parsedLength);
|
|
69
67
|
// Find what might be the end of the current list (or might be the end of a nested list)
|
|
70
68
|
let nextListEnd;
|
|
71
69
|
switch (currentListType) {
|
|
@@ -89,7 +87,6 @@ let RichTextService = class RichTextService {
|
|
|
89
87
|
// We've found the start of a list
|
|
90
88
|
newHtml += `<ol>`;
|
|
91
89
|
const listTagEnd = html.indexOf('>', nextItemPos);
|
|
92
|
-
console.log(`-----> listTagEnd ${listTagEnd}`);
|
|
93
90
|
if (listTagEnd === -1) {
|
|
94
91
|
// Invalid HTML. Dump the lot.
|
|
95
92
|
return '';
|
|
@@ -98,12 +95,10 @@ let RichTextService = class RichTextService {
|
|
|
98
95
|
if (nextItemPos === olStart) {
|
|
99
96
|
listStack.push('ol');
|
|
100
97
|
currentListType = 'ol';
|
|
101
|
-
console.log(`-----> push ol`);
|
|
102
98
|
}
|
|
103
99
|
else {
|
|
104
100
|
listStack.push('ul');
|
|
105
101
|
currentListType = 'ul';
|
|
106
|
-
console.log(`-----> push ul`);
|
|
107
102
|
}
|
|
108
103
|
break;
|
|
109
104
|
case liStart:
|
|
@@ -129,10 +124,8 @@ let RichTextService = class RichTextService {
|
|
|
129
124
|
// We've reached the end of the current list. Write out the closing tag and pop the stack
|
|
130
125
|
newHtml += olEndTag;
|
|
131
126
|
parsedLength = nextListEnd + olEndTag.length;
|
|
132
|
-
console.log(`-----> pop ${listStack[listStack.length - 1]}`);
|
|
133
127
|
listStack.pop();
|
|
134
128
|
currentListType = listStack[listStack.length - 1];
|
|
135
|
-
console.log(`-----> (now in ${currentListType})`);
|
|
136
129
|
break;
|
|
137
130
|
}
|
|
138
131
|
}
|
|
@@ -140,7 +133,6 @@ let RichTextService = class RichTextService {
|
|
|
140
133
|
// We didn't close the last list. Invalid HTML. Dump the lot.
|
|
141
134
|
return '';
|
|
142
135
|
}
|
|
143
|
-
console.log(`-----> newHtml`, newHtml);
|
|
144
136
|
return newHtml;
|
|
145
137
|
}
|
|
146
138
|
/**
|
|
@@ -227,6 +219,14 @@ let RichTextService = class RichTextService {
|
|
|
227
219
|
}
|
|
228
220
|
return html;
|
|
229
221
|
}
|
|
222
|
+
/** Helper method because regexes can't natively start searching from a given index */
|
|
223
|
+
indexOfRegex(text, regex, fromIndex) {
|
|
224
|
+
const match = text.substring(fromIndex).match(regex);
|
|
225
|
+
if (!match || match.index === undefined || match.index === -1) {
|
|
226
|
+
return -1;
|
|
227
|
+
}
|
|
228
|
+
return fromIndex + match.index;
|
|
229
|
+
}
|
|
230
230
|
/** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
|
|
231
231
|
removeCursor(html) {
|
|
232
232
|
if (!html) {
|
|
@@ -243,14 +243,9 @@ let RichTextService = class RichTextService {
|
|
|
243
243
|
}
|
|
244
244
|
/** Clean up the HTML, ready for save */
|
|
245
245
|
sanitizeHtml(html) {
|
|
246
|
-
console.log(`-----> -------------`);
|
|
247
|
-
console.log(`-----> html initial (${html.length}) ${html}`);
|
|
248
246
|
html = this.removeZeroWidthNoBreakSpaces(html);
|
|
249
|
-
console.log(`-----> after removeZeroWidthNoBreakSpaces (${html.length}) ${html}`);
|
|
250
247
|
html = this.removeCursor(html);
|
|
251
|
-
console.log(`-----> after removeCursor (${html.length}) ${html}`);
|
|
252
248
|
html = this.$sanitize(html);
|
|
253
|
-
console.log(`-----> after $sanitize (${html.length}) ${html}`);
|
|
254
249
|
return html;
|
|
255
250
|
}
|
|
256
251
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-text.service.js","sourceRoot":"","sources":["../../src/components/rich-text/rich-text.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAA2C;AAC3C,8CAAkD;AAElD,8GAA8G;AAC9G,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAmB,EAAE,CAAC,iBAAgD,EAAE,EAAE;QACvG,iBAAiB,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;QAE1C,0GAA0G;QAC1G,iBAAiB,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAC,CAAA;AAGH,IAAqB,eAAe,GAApC,MAAqB,eAAe;IAEnC,YAC8B,SAAoC;QAApC,cAAS,GAAT,SAAS,CAA2B;IAC9D,CAAC;IAEL,gFAAgF;IAChF,uBAAuB,CAAC,IAAY;QAEnC,
|
|
1
|
+
{"version":3,"file":"rich-text.service.js","sourceRoot":"","sources":["../../src/components/rich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K,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,EAAE;YAC9D,OAAO,CAAC,CAAC,CAAA;SACT;QACD,OAAO,SAAS,GAAG,KAAK,CAAC,KAAK,CAAA;IAC/B,CAAC;IAED,kFAAkF;IAClF,YAAY,CAAC,IAAY;QAExB,IAAI,CAAC,IAAI,EAAE;YACV,OAAO,IAAI,CAAA;SACX;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,yCAAyC,EAAE,EAAE,CAAC,CAAA;IACnE,CAAC;IAED,uDAAuD;IACvD,4BAA4B,CAAC,IAAY;QAExC,IAAI,CAAC,IAAI,EAAE;YACV,OAAO,IAAI,CAAA;SACX;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,wCAAwC;IACxC,YAAY,CAAC,IAAY;QAExB,IAAI,GAAG,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAE3B,OAAO,IAAI,CAAA;IACZ,CAAC;CAED,CAAA;AAvRoB,eAAe;IADnC,uBAAU,CAAC,iBAAiB,CAAC;IAI3B,WAAA,mBAAM,CAAC,WAAW,CAAC,CAAA;;GAHD,eAAe,CAuRnC;kBAvRoB,eAAe"}
|
|
@@ -1382,8 +1382,8 @@
|
|
|
1382
1382
|
"affectsGlobalScope": false
|
|
1383
1383
|
},
|
|
1384
1384
|
"../src/components/rich-text/rich-text.service.ts": {
|
|
1385
|
-
"version": "
|
|
1386
|
-
"signature": "
|
|
1385
|
+
"version": "de1ea19e846a8fd46cd4e267f2eba41bdaac52cb0c27a98ebfb4a64bc2d46c8a",
|
|
1386
|
+
"signature": "92f2944369f0ab53daa589de0069dbd688594e3d7d4f4eae4af2ae1fa20b2423",
|
|
1387
1387
|
"affectsGlobalScope": false
|
|
1388
1388
|
},
|
|
1389
1389
|
"../src/components/rich-text/rich-text.component.ts": {
|
package/package.json
CHANGED
|
@@ -19,15 +19,10 @@ export default class RichTextService {
|
|
|
19
19
|
/** Older versions of Quill rendered some things differently. Patch those up. */
|
|
20
20
|
backwardsCompatibleHtml(html: string): string {
|
|
21
21
|
|
|
22
|
-
console.log(`-----> backwardsCompatibleHtml (${html.length}) ${html}`)
|
|
23
22
|
html = this.removeZeroWidthNoBreakSpaces(html)
|
|
24
|
-
console.log(`-----> after removeZeroWidthNoBreakSpaces (${html.length}) ${html}`)
|
|
25
23
|
html = this.removeCursor(html)
|
|
26
|
-
console.log(`-----> after removeCursor (${html.length}) ${html}`)
|
|
27
24
|
html = this.fixWrappingCursor(html)
|
|
28
|
-
console.log(`-----> after fixWrappingCursor (${html.length}) ${html}`)
|
|
29
25
|
html = this.fixFontTags(html)
|
|
30
|
-
console.log(`-----> after fixFontTags (${html.length}) ${html}`)
|
|
31
26
|
html = this.fixBulletPoints(html)
|
|
32
27
|
|
|
33
28
|
return html
|
|
@@ -40,31 +35,34 @@ export default class RichTextService {
|
|
|
40
35
|
*/
|
|
41
36
|
fixBulletPoints(html: string): string {
|
|
42
37
|
|
|
43
|
-
console.log(`-----> fixBulletPoints`, html)
|
|
44
|
-
|
|
45
38
|
if (!html) {
|
|
46
39
|
return html
|
|
47
40
|
}
|
|
48
41
|
|
|
49
42
|
let newHtml: string = ''
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
// Regexes for these, in case someone invents a <link> tag or something
|
|
45
|
+
const olStartTagRegex = new RegExp(`<ol( |>)`)
|
|
46
|
+
const ulStartTagRegex = new RegExp(`<ul( |>)`)
|
|
47
|
+
const liStartTagRegex = new RegExp(`<li( |>)`)
|
|
48
|
+
// Literal string matches for these
|
|
52
49
|
const olEndTag = `</ol>`
|
|
53
|
-
const ulStartTag = `<ul`
|
|
54
50
|
const ulEndTag = `</ul>`
|
|
55
|
-
const liStartTag = `<li`
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
// Stack of <ol> and <ul> tags, representing how the lists are nested
|
|
53
|
+
const listStack: string[] = []
|
|
58
54
|
|
|
59
55
|
let parsedLength = 0
|
|
60
56
|
let currentListType: string | undefined
|
|
57
|
+
|
|
58
|
+
// Loop through the input html, looking for <ol>, <ul> and <li> tags. Maintain a stack of nested lists, so
|
|
59
|
+
// we can transform the current <li> correctly.
|
|
61
60
|
while (parsedLength < html.length) {
|
|
62
|
-
console.log(`-----> parsedLength ${parsedLength}`)
|
|
63
61
|
|
|
64
62
|
// Find the start of the next <ol>, <ul> or <li> tag
|
|
65
|
-
const olStart =
|
|
66
|
-
const ulStart =
|
|
67
|
-
const liStart =
|
|
63
|
+
const olStart = this.indexOfRegex(html, olStartTagRegex, parsedLength)
|
|
64
|
+
const ulStart = this.indexOfRegex(html, ulStartTagRegex, parsedLength)
|
|
65
|
+
const liStart = this.indexOfRegex(html, liStartTagRegex, parsedLength)
|
|
68
66
|
|
|
69
67
|
// Find what might be the end of the current list (or might be the end of a nested list)
|
|
70
68
|
let nextListEnd: number
|
|
@@ -97,7 +95,6 @@ export default class RichTextService {
|
|
|
97
95
|
newHtml += `<ol>`
|
|
98
96
|
|
|
99
97
|
const listTagEnd = html.indexOf('>', nextItemPos)
|
|
100
|
-
console.log(`-----> listTagEnd ${listTagEnd}`)
|
|
101
98
|
if (listTagEnd === -1) {
|
|
102
99
|
// Invalid HTML. Dump the lot.
|
|
103
100
|
return ''
|
|
@@ -107,11 +104,9 @@ export default class RichTextService {
|
|
|
107
104
|
if (nextItemPos === olStart) {
|
|
108
105
|
listStack.push('ol')
|
|
109
106
|
currentListType = 'ol'
|
|
110
|
-
console.log(`-----> push ol`)
|
|
111
107
|
} else {
|
|
112
108
|
listStack.push('ul')
|
|
113
109
|
currentListType = 'ul'
|
|
114
|
-
console.log(`-----> push ul`)
|
|
115
110
|
}
|
|
116
111
|
break
|
|
117
112
|
|
|
@@ -142,10 +137,8 @@ export default class RichTextService {
|
|
|
142
137
|
// We've reached the end of the current list. Write out the closing tag and pop the stack
|
|
143
138
|
newHtml += olEndTag
|
|
144
139
|
parsedLength = nextListEnd + olEndTag.length
|
|
145
|
-
console.log(`-----> pop ${listStack[listStack.length - 1]}`)
|
|
146
140
|
listStack.pop()
|
|
147
141
|
currentListType = listStack[listStack.length - 1]
|
|
148
|
-
console.log(`-----> (now in ${currentListType})`)
|
|
149
142
|
break
|
|
150
143
|
}
|
|
151
144
|
}
|
|
@@ -155,7 +148,6 @@ export default class RichTextService {
|
|
|
155
148
|
return ''
|
|
156
149
|
}
|
|
157
150
|
|
|
158
|
-
console.log(`-----> newHtml`, newHtml)
|
|
159
151
|
return newHtml
|
|
160
152
|
}
|
|
161
153
|
|
|
@@ -257,6 +249,16 @@ export default class RichTextService {
|
|
|
257
249
|
return html
|
|
258
250
|
}
|
|
259
251
|
|
|
252
|
+
/** Helper method because regexes can't natively start searching from a given index */
|
|
253
|
+
indexOfRegex(text: string, regex: RegExp, fromIndex: number): number {
|
|
254
|
+
|
|
255
|
+
const match = text.substring(fromIndex).match(regex)
|
|
256
|
+
if (!match || match.index === undefined || match.index === -1) {
|
|
257
|
+
return -1
|
|
258
|
+
}
|
|
259
|
+
return fromIndex + match.index
|
|
260
|
+
}
|
|
261
|
+
|
|
260
262
|
/** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
|
|
261
263
|
removeCursor(html: string): string {
|
|
262
264
|
|
|
@@ -280,14 +282,9 @@ export default class RichTextService {
|
|
|
280
282
|
/** Clean up the HTML, ready for save */
|
|
281
283
|
sanitizeHtml(html: string): string {
|
|
282
284
|
|
|
283
|
-
console.log(`-----> -------------`)
|
|
284
|
-
console.log(`-----> html initial (${html.length}) ${html}`)
|
|
285
285
|
html = this.removeZeroWidthNoBreakSpaces(html)
|
|
286
|
-
console.log(`-----> after removeZeroWidthNoBreakSpaces (${html.length}) ${html}`)
|
|
287
286
|
html = this.removeCursor(html)
|
|
288
|
-
console.log(`-----> after removeCursor (${html.length}) ${html}`)
|
|
289
287
|
html = this.$sanitize(html)
|
|
290
|
-
console.log(`-----> after $sanitize (${html.length}) ${html}`)
|
|
291
288
|
|
|
292
289
|
return html
|
|
293
290
|
}
|