@mediafly/js-ui 51.2.1 → 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.
@@ -5,6 +5,12 @@ export default class RichTextService {
5
5
  constructor($sanitize: sanitize.ISanitizeService);
6
6
  /** Older versions of Quill rendered some things differently. Patch those up. */
7
7
  backwardsCompatibleHtml(html: string): string;
8
+ /**
9
+ * Transform <ul><li> into <ol><li data-list="bullet">,
10
+ * and <ol><li> into <ol><li data-list="ordered">
11
+ * accounting for any pattern of nested <ul> and <ol> tags.
12
+ */
13
+ fixBulletPoints(html: string): string;
8
14
  /**
9
15
  * Transform <font> tags from the old Quill editor into <span> tags, as used by the new editor.
10
16
  * Quill used to set fonts using <font color="#000000" face="Open Sans">
@@ -18,6 +24,8 @@ export default class RichTextService {
18
24
  * In rare cases, the HTML wraps that span around actual content. This function fixes that.
19
25
  */
20
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;
21
29
  /** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
22
30
  removeCursor(html: string): string;
23
31
  /** Sometimes Quill adds Zero Width No-Break Spaces. */
@@ -33,8 +33,108 @@ let RichTextService = class RichTextService {
33
33
  html = this.removeCursor(html);
34
34
  html = this.fixWrappingCursor(html);
35
35
  html = this.fixFontTags(html);
36
+ html = this.fixBulletPoints(html);
36
37
  return html;
37
38
  }
39
+ /**
40
+ * Transform <ul><li> into <ol><li data-list="bullet">,
41
+ * and <ol><li> into <ol><li data-list="ordered">
42
+ * accounting for any pattern of nested <ul> and <ol> tags.
43
+ */
44
+ fixBulletPoints(html) {
45
+ if (!html) {
46
+ return html;
47
+ }
48
+ let newHtml = '';
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
54
+ const olEndTag = `</ol>`;
55
+ const ulEndTag = `</ul>`;
56
+ // Stack of <ol> and <ul> tags, representing how the lists are nested
57
+ const listStack = [];
58
+ let parsedLength = 0;
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.
62
+ while (parsedLength < html.length) {
63
+ // Find the start of the next <ol>, <ul> or <li> tag
64
+ const olStart = this.indexOfRegex(html, olStartTagRegex, parsedLength);
65
+ const ulStart = this.indexOfRegex(html, ulStartTagRegex, parsedLength);
66
+ const liStart = this.indexOfRegex(html, liStartTagRegex, parsedLength);
67
+ // Find what might be the end of the current list (or might be the end of a nested list)
68
+ let nextListEnd;
69
+ switch (currentListType) {
70
+ case 'ol':
71
+ nextListEnd = html.indexOf(olEndTag, parsedLength);
72
+ break;
73
+ case 'ul':
74
+ nextListEnd = html.indexOf(ulEndTag, parsedLength);
75
+ break;
76
+ default:
77
+ nextListEnd = -1;
78
+ break;
79
+ }
80
+ // Find which tag comes next
81
+ const nextItemPos = Math.min(olStart === -1 ? html.length : olStart, ulStart === -1 ? html.length : ulStart, liStart === -1 ? html.length : liStart, nextListEnd === -1 ? html.length : nextListEnd);
82
+ newHtml += html.substring(parsedLength, nextItemPos);
83
+ parsedLength = nextItemPos;
84
+ switch (nextItemPos) {
85
+ case olStart:
86
+ case ulStart:
87
+ // We've found the start of a list
88
+ newHtml += `<ol>`;
89
+ const listTagEnd = html.indexOf('>', nextItemPos);
90
+ if (listTagEnd === -1) {
91
+ // Invalid HTML. Dump the lot.
92
+ return '';
93
+ }
94
+ parsedLength = listTagEnd + 1;
95
+ if (nextItemPos === olStart) {
96
+ listStack.push('ol');
97
+ currentListType = 'ol';
98
+ }
99
+ else {
100
+ listStack.push('ul');
101
+ currentListType = 'ul';
102
+ }
103
+ break;
104
+ case liStart:
105
+ // We've found a list item
106
+ if (!currentListType) {
107
+ // Invalid HTML. Dump the lot.
108
+ return '';
109
+ }
110
+ const liTagEnd = html.indexOf('>', liStart + 1);
111
+ if (liTagEnd === -1) {
112
+ // Invalid HTML. Dump the lot.
113
+ return '';
114
+ }
115
+ let liTag = html.substring(liStart, liTagEnd + 1);
116
+ if (liTag.indexOf('data-list') === -1) {
117
+ const dataAttr = ` data-list="${currentListType === 'ol' ? 'ordered' : 'bullet'}"`;
118
+ liTag = `<li${dataAttr}` + liTag.substring(3);
119
+ }
120
+ newHtml += liTag;
121
+ parsedLength = liTagEnd + 1;
122
+ break;
123
+ case nextListEnd:
124
+ // We've reached the end of the current list. Write out the closing tag and pop the stack
125
+ newHtml += olEndTag;
126
+ parsedLength = nextListEnd + olEndTag.length;
127
+ listStack.pop();
128
+ currentListType = listStack[listStack.length - 1];
129
+ break;
130
+ }
131
+ }
132
+ if (listStack.length > 0) {
133
+ // We didn't close the last list. Invalid HTML. Dump the lot.
134
+ return '';
135
+ }
136
+ return newHtml;
137
+ }
38
138
  /**
39
139
  * Transform <font> tags from the old Quill editor into <span> tags, as used by the new editor.
40
140
  * Quill used to set fonts using <font color="#000000" face="Open Sans">
@@ -119,6 +219,14 @@ let RichTextService = class RichTextService {
119
219
  }
120
220
  return html;
121
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
+ }
122
230
  /** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
123
231
  removeCursor(html) {
124
232
  if (!html) {
@@ -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,MA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,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"}
@@ -1297,8 +1297,8 @@
1297
1297
  "affectsGlobalScope": false
1298
1298
  },
1299
1299
  "../node_modules/quill/core/module.d.ts": {
1300
- "version": "1fa363695d7a5633ca82cce91c93cc9e7b4972a751a9983b0660c3cd0265787d",
1301
- "signature": "1fa363695d7a5633ca82cce91c93cc9e7b4972a751a9983b0660c3cd0265787d",
1300
+ "version": "d63b8f8ee9d8be8da2b7c8320b6238687d5c6b4c2fff451656a76675ce02b0fa",
1301
+ "signature": "d63b8f8ee9d8be8da2b7c8320b6238687d5c6b4c2fff451656a76675ce02b0fa",
1302
1302
  "affectsGlobalScope": false
1303
1303
  },
1304
1304
  "../node_modules/quill/blots/embed.d.ts": {
@@ -1352,8 +1352,8 @@
1352
1352
  "affectsGlobalScope": false
1353
1353
  },
1354
1354
  "../node_modules/quill/modules/toolbar.d.ts": {
1355
- "version": "2589c2de539ffb71312229513d47d63843bc72213c4174af4c543cf99b8fdede",
1356
- "signature": "2589c2de539ffb71312229513d47d63843bc72213c4174af4c543cf99b8fdede",
1355
+ "version": "41531d66ecc0d7b8b6511b013597170807bb3862dd94a4a6c32dd831d83a26a2",
1356
+ "signature": "41531d66ecc0d7b8b6511b013597170807bb3862dd94a4a6c32dd831d83a26a2",
1357
1357
  "affectsGlobalScope": false
1358
1358
  },
1359
1359
  "../node_modules/quill/core/theme.d.ts": {
@@ -1367,23 +1367,23 @@
1367
1367
  "affectsGlobalScope": false
1368
1368
  },
1369
1369
  "../node_modules/quill/core/quill.d.ts": {
1370
- "version": "f532b3b3df9d5c950b8c952a350df4361b9acac8ea552172f56387b3a067b1bd",
1371
- "signature": "f532b3b3df9d5c950b8c952a350df4361b9acac8ea552172f56387b3a067b1bd",
1370
+ "version": "27805c27fe815e9311d06d4b489965662d197ce055be3224e0890d0511ffbefc",
1371
+ "signature": "27805c27fe815e9311d06d4b489965662d197ce055be3224e0890d0511ffbefc",
1372
1372
  "affectsGlobalScope": false
1373
1373
  },
1374
1374
  "../node_modules/quill/core.d.ts": {
1375
- "version": "0a258caef8e04ec13e4bdbc3daad6f3457088a97ab34564488dc304cba8c1395",
1376
- "signature": "0a258caef8e04ec13e4bdbc3daad6f3457088a97ab34564488dc304cba8c1395",
1375
+ "version": "3668fab5115de694079d3c99f07dcee9ec461910d5c2710aa6e41684a37f494f",
1376
+ "signature": "3668fab5115de694079d3c99f07dcee9ec461910d5c2710aa6e41684a37f494f",
1377
1377
  "affectsGlobalScope": false
1378
1378
  },
1379
1379
  "../node_modules/quill/quill.d.ts": {
1380
- "version": "caffa9bae19fb2e9a234363be7bd665c4fd4db699a3f5d1f68f11494682269af",
1381
- "signature": "caffa9bae19fb2e9a234363be7bd665c4fd4db699a3f5d1f68f11494682269af",
1380
+ "version": "4abcf2cd22461f6a1a47f413a39b36a72ec2ae701ceaadb88fa76e923f720152",
1381
+ "signature": "4abcf2cd22461f6a1a47f413a39b36a72ec2ae701ceaadb88fa76e923f720152",
1382
1382
  "affectsGlobalScope": false
1383
1383
  },
1384
1384
  "../src/components/rich-text/rich-text.service.ts": {
1385
- "version": "0bc07cb7ed1ba52cafd0c0b1b45345d84ee18386d13f0517fe8905966f7e4746",
1386
- "signature": "90e3c7c57ec4c9dcbe75bc82118788f36ca4266ed86ce71fea4239435bffc687",
1385
+ "version": "de1ea19e846a8fd46cd4e267f2eba41bdaac52cb0c27a98ebfb4a64bc2d46c8a",
1386
+ "signature": "92f2944369f0ab53daa589de0069dbd688594e3d7d4f4eae4af2ae1fa20b2423",
1387
1387
  "affectsGlobalScope": false
1388
1388
  },
1389
1389
  "../src/components/rich-text/rich-text.component.ts": {
@@ -3332,6 +3332,7 @@
3332
3332
  ],
3333
3333
  "../node_modules/quill/core.d.ts": [
3334
3334
  "../node_modules/quill-delta/dist/delta.d.ts",
3335
+ "../node_modules/quill/core/module.d.ts",
3335
3336
  "../node_modules/quill/core/quill.d.ts"
3336
3337
  ],
3337
3338
  "../node_modules/quill/core/composition.d.ts": [
@@ -5186,6 +5187,7 @@
5186
5187
  ],
5187
5188
  "../node_modules/quill/core.d.ts": [
5188
5189
  "../node_modules/quill-delta/dist/delta.d.ts",
5190
+ "../node_modules/quill/core/module.d.ts",
5189
5191
  "../node_modules/quill/core/quill.d.ts"
5190
5192
  ],
5191
5193
  "../node_modules/quill/core/composition.d.ts": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediafly/js-ui",
3
- "version": "51.2.1",
3
+ "version": "51.2.2-1",
4
4
  "license": "UNLICENSED",
5
5
  "description": "UI components for Mediafly Angular applications",
6
6
  "repository": {
@@ -23,10 +23,134 @@ export default class RichTextService {
23
23
  html = this.removeCursor(html)
24
24
  html = this.fixWrappingCursor(html)
25
25
  html = this.fixFontTags(html)
26
+ html = this.fixBulletPoints(html)
26
27
 
27
28
  return html
28
29
  }
29
30
 
31
+ /**
32
+ * Transform <ul><li> into <ol><li data-list="bullet">,
33
+ * and <ol><li> into <ol><li data-list="ordered">
34
+ * accounting for any pattern of nested <ul> and <ol> tags.
35
+ */
36
+ fixBulletPoints(html: string): string {
37
+
38
+ if (!html) {
39
+ return html
40
+ }
41
+
42
+ let newHtml: string = ''
43
+
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
49
+ const olEndTag = `</ol>`
50
+ const ulEndTag = `</ul>`
51
+
52
+ // Stack of <ol> and <ul> tags, representing how the lists are nested
53
+ const listStack: string[] = []
54
+
55
+ let parsedLength = 0
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.
60
+ while (parsedLength < html.length) {
61
+
62
+ // Find the start of the next <ol>, <ul> or <li> tag
63
+ const olStart = this.indexOfRegex(html, olStartTagRegex, parsedLength)
64
+ const ulStart = this.indexOfRegex(html, ulStartTagRegex, parsedLength)
65
+ const liStart = this.indexOfRegex(html, liStartTagRegex, parsedLength)
66
+
67
+ // Find what might be the end of the current list (or might be the end of a nested list)
68
+ let nextListEnd: number
69
+ switch (currentListType) {
70
+ case 'ol':
71
+ nextListEnd = html.indexOf(olEndTag, parsedLength)
72
+ break
73
+ case 'ul':
74
+ nextListEnd = html.indexOf(ulEndTag, parsedLength)
75
+ break
76
+ default:
77
+ nextListEnd = -1
78
+ break
79
+ }
80
+
81
+ // Find which tag comes next
82
+ const nextItemPos = Math.min(
83
+ olStart === -1 ? html.length : olStart,
84
+ ulStart === -1 ? html.length : ulStart,
85
+ liStart === -1 ? html.length : liStart,
86
+ nextListEnd === -1 ? html.length : nextListEnd)
87
+
88
+ newHtml += html.substring(parsedLength, nextItemPos)
89
+ parsedLength = nextItemPos
90
+
91
+ switch (nextItemPos) {
92
+ case olStart:
93
+ case ulStart:
94
+ // We've found the start of a list
95
+ newHtml += `<ol>`
96
+
97
+ const listTagEnd = html.indexOf('>', nextItemPos)
98
+ if (listTagEnd === -1) {
99
+ // Invalid HTML. Dump the lot.
100
+ return ''
101
+ }
102
+ parsedLength = listTagEnd + 1
103
+
104
+ if (nextItemPos === olStart) {
105
+ listStack.push('ol')
106
+ currentListType = 'ol'
107
+ } else {
108
+ listStack.push('ul')
109
+ currentListType = 'ul'
110
+ }
111
+ break
112
+
113
+ case liStart:
114
+ // We've found a list item
115
+ if (!currentListType) {
116
+ // Invalid HTML. Dump the lot.
117
+ return ''
118
+ }
119
+
120
+ const liTagEnd = html.indexOf('>', liStart + 1)
121
+ if (liTagEnd === -1) {
122
+ // Invalid HTML. Dump the lot.
123
+ return ''
124
+ }
125
+ let liTag = html.substring(liStart, liTagEnd + 1)
126
+
127
+ if (liTag.indexOf('data-list') === -1) {
128
+ const dataAttr = ` data-list="${currentListType === 'ol' ? 'ordered' : 'bullet'}"`
129
+ liTag = `<li${dataAttr}` + liTag.substring(3)
130
+ }
131
+
132
+ newHtml += liTag
133
+ parsedLength = liTagEnd + 1
134
+ break
135
+
136
+ case nextListEnd:
137
+ // We've reached the end of the current list. Write out the closing tag and pop the stack
138
+ newHtml += olEndTag
139
+ parsedLength = nextListEnd + olEndTag.length
140
+ listStack.pop()
141
+ currentListType = listStack[listStack.length - 1]
142
+ break
143
+ }
144
+ }
145
+
146
+ if (listStack.length > 0) {
147
+ // We didn't close the last list. Invalid HTML. Dump the lot.
148
+ return ''
149
+ }
150
+
151
+ return newHtml
152
+ }
153
+
30
154
  /**
31
155
  * Transform <font> tags from the old Quill editor into <span> tags, as used by the new editor.
32
156
  * Quill used to set fonts using <font color="#000000" face="Open Sans">
@@ -125,6 +249,16 @@ export default class RichTextService {
125
249
  return html
126
250
  }
127
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
+
128
262
  /** Sometimes Quill's HTML includes its own cursor. We don't want to save that. */
129
263
  removeCursor(html: string): string {
130
264