@globalpayments/vega 2.34.0 → 2.34.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.
Files changed (122) hide show
  1. package/dist/cjs/{app-globals-4e819773.js → app-globals-48582633.js} +2 -2
  2. package/dist/cjs/{content-state-3a2724f6.js → content-state-6a5b9736.js} +64 -294
  3. package/dist/cjs/index.cjs.js +2 -2
  4. package/dist/cjs/loader.cjs.js +3 -3
  5. package/dist/cjs/{text-color-toolbar-button-slimmer-b1c9f40e.js → text-color-toolbar-button-slimmer-21a166e4.js} +1 -1
  6. package/dist/cjs/{text-node-0d12da5a.js → text-node-494856f3.js} +0 -122
  7. package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
  8. package/dist/cjs/vega-pagination.cjs.entry.js +5 -2
  9. package/dist/cjs/vega-rich-text-content.cjs.entry.js +2 -2
  10. package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +629 -416
  11. package/dist/cjs/vega-table_8.cjs.entry.js +1 -1
  12. package/dist/cjs/vega.cjs.js +3 -3
  13. package/dist/collection/components/vega-pagination/vega-pagination.js +5 -2
  14. package/dist/collection/components/vega-rich-text-editor/dto/annotations/bold-annotation.js +0 -10
  15. package/dist/collection/components/vega-rich-text-editor/dto/annotations/code-annotation.js +0 -9
  16. package/dist/collection/components/vega-rich-text-editor/dto/annotations/horizontal-alignment-annotation.js +0 -44
  17. package/dist/collection/components/vega-rich-text-editor/dto/annotations/image-annotation.js +0 -10
  18. package/dist/collection/components/vega-rich-text-editor/dto/annotations/indent-annotation.js +0 -42
  19. package/dist/collection/components/vega-rich-text-editor/dto/annotations/italic-annotation.js +0 -9
  20. package/dist/collection/components/vega-rich-text-editor/dto/annotations/link-annotation.js +0 -14
  21. package/dist/collection/components/vega-rich-text-editor/dto/annotations/strikethrough-annotation.js +0 -11
  22. package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-color-annotation.js +0 -26
  23. package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-style-annotation.js +0 -44
  24. package/dist/collection/components/vega-rich-text-editor/dto/annotations/underline-annotation.js +0 -11
  25. package/dist/collection/components/vega-rich-text-editor/dto/blocks/block.abstract.js +0 -18
  26. package/dist/collection/components/vega-rich-text-editor/dto/blocks/image-block.js +0 -13
  27. package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-block.js +0 -19
  28. package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-item-block.js +0 -27
  29. package/dist/collection/components/vega-rich-text-editor/dto/blocks/text-block.js +2 -14
  30. package/dist/collection/components/vega-rich-text-editor/dto/nodes/image-node.js +0 -10
  31. package/dist/collection/components/vega-rich-text-editor/dto/nodes/text-node.js +0 -32
  32. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/block-to-rte-block-strategy.abstract.js +258 -0
  33. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.js +71 -0
  34. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy-processor.js +70 -0
  35. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy.abstract.js +37 -0
  36. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/img-to-rte-image-block-strategy.js +55 -0
  37. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/inline-block-to-rte-text-block-strategy.js +85 -0
  38. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/li-to-rte-list-item-block-strategy.js +49 -0
  39. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ol-to-rte-list-block-strategy.js +50 -0
  40. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/span-img-to-rte-image-block-strategy.js +60 -0
  41. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ul-to-rte-list-block-strategy.js +50 -0
  42. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/vega-image-to-rte-image-block-strategy.js +56 -0
  43. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/input-event-handler/insert-paste-handler.js +7 -3
  44. package/dist/collection/components/vega-table/vega-table-head-cell/vega-table-head-cell.css +3 -0
  45. package/dist/esm/{app-globals-9971ccfd.js → app-globals-48531a04.js} +2 -2
  46. package/dist/esm/{content-state-acf55eb0.js → content-state-4b036bf1.js} +65 -295
  47. package/dist/esm/index.js +2 -2
  48. package/dist/esm/loader.js +3 -3
  49. package/dist/esm/{text-color-toolbar-button-slimmer-d0255b98.js → text-color-toolbar-button-slimmer-b2270b64.js} +1 -1
  50. package/dist/esm/{text-node-6f7d736c.js → text-node-a652ca87.js} +0 -122
  51. package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
  52. package/dist/esm/vega-pagination.entry.js +5 -2
  53. package/dist/esm/vega-rich-text-content.entry.js +2 -2
  54. package/dist/esm/vega-rich-text-editor_4.entry.js +630 -417
  55. package/dist/esm/vega-table_8.entry.js +1 -1
  56. package/dist/esm/vega.js +3 -3
  57. package/dist/types/components/vega-pagination/vega-pagination.d.ts +1 -0
  58. package/dist/types/components/vega-rich-text-editor/dto/annotations/bold-annotation.d.ts +0 -7
  59. package/dist/types/components/vega-rich-text-editor/dto/annotations/code-annotation.d.ts +0 -7
  60. package/dist/types/components/vega-rich-text-editor/dto/annotations/horizontal-alignment-annotation.d.ts +0 -14
  61. package/dist/types/components/vega-rich-text-editor/dto/annotations/image-annotation.d.ts +0 -8
  62. package/dist/types/components/vega-rich-text-editor/dto/annotations/indent-annotation.d.ts +0 -14
  63. package/dist/types/components/vega-rich-text-editor/dto/annotations/italic-annotation.d.ts +0 -7
  64. package/dist/types/components/vega-rich-text-editor/dto/annotations/link-annotation.d.ts +0 -7
  65. package/dist/types/components/vega-rich-text-editor/dto/annotations/strikethrough-annotation.d.ts +0 -7
  66. package/dist/types/components/vega-rich-text-editor/dto/annotations/text-color-annotation.d.ts +0 -7
  67. package/dist/types/components/vega-rich-text-editor/dto/annotations/text-style-annotation.d.ts +0 -14
  68. package/dist/types/components/vega-rich-text-editor/dto/annotations/underline-annotation.d.ts +0 -7
  69. package/dist/types/components/vega-rich-text-editor/dto/blocks/block.abstract.d.ts +0 -8
  70. package/dist/types/components/vega-rich-text-editor/dto/blocks/image-block.d.ts +0 -1
  71. package/dist/types/components/vega-rich-text-editor/dto/blocks/list-block.d.ts +0 -1
  72. package/dist/types/components/vega-rich-text-editor/dto/blocks/list-item-block.d.ts +0 -1
  73. package/dist/types/components/vega-rich-text-editor/dto/blocks/text-block.d.ts +0 -1
  74. package/dist/types/components/vega-rich-text-editor/dto/nodes/image-node.d.ts +0 -1
  75. package/dist/types/components/vega-rich-text-editor/dto/nodes/text-node.d.ts +0 -2
  76. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/block-to-rte-block-strategy.abstract.d.ts +111 -0
  77. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.d.ts +32 -0
  78. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy-processor.d.ts +19 -0
  79. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy.abstract.d.ts +32 -0
  80. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/img-to-rte-image-block-strategy.d.ts +31 -0
  81. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/inline-block-to-rte-text-block-strategy.d.ts +38 -0
  82. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/li-to-rte-list-item-block-strategy.d.ts +35 -0
  83. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ol-to-rte-list-block-strategy.d.ts +36 -0
  84. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/span-img-to-rte-image-block-strategy.d.ts +31 -0
  85. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ul-to-rte-list-block-strategy.d.ts +36 -0
  86. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/vega-image-to-rte-image-block-strategy.d.ts +31 -0
  87. package/dist/vega/index.esm.js +1 -1
  88. package/dist/vega/{p-d302f052.entry.js → p-0190095c.entry.js} +1 -1
  89. package/dist/vega/p-10393104.js +1 -0
  90. package/dist/vega/p-584dcd9b.js +1 -0
  91. package/dist/vega/p-5f377954.js +1 -1
  92. package/dist/vega/{p-c1d97d12.entry.js → p-734ea281.entry.js} +1 -1
  93. package/dist/vega/{p-49f4a666.js → p-8836c1b9.js} +1 -1
  94. package/dist/vega/p-8f004647.entry.js +1 -0
  95. package/dist/vega/p-9e732a26.entry.js +1 -0
  96. package/dist/vega/{p-2fc3af2f.js → p-9f39dd10.js} +1 -1
  97. package/dist/vega/vega.esm.js +1 -1
  98. package/package.json +1 -1
  99. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-handler.abstract.js +0 -135
  100. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-processor.js +0 -74
  101. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/image-to-dto-handler.js +0 -47
  102. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/inline-block-to-dto-handler.js +0 -39
  103. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/link-to-dto-handler.js +0 -50
  104. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-item-to-dto-handler.js +0 -41
  105. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-to-dto-handler.js +0 -57
  106. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/paragraph-to-dto-handler.js +0 -56
  107. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-block-to-dto-handler.js +0 -77
  108. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-to-dto-handler.js +0 -44
  109. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-handler.abstract.d.ts +0 -67
  110. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-processor.d.ts +0 -29
  111. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/image-to-dto-handler.d.ts +0 -37
  112. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/inline-block-to-dto-handler.d.ts +0 -35
  113. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/link-to-dto-handler.d.ts +0 -37
  114. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-item-to-dto-handler.d.ts +0 -36
  115. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-to-dto-handler.d.ts +0 -39
  116. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/paragraph-to-dto-handler.d.ts +0 -39
  117. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-block-to-dto-handler.d.ts +0 -46
  118. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-to-dto-handler.d.ts +0 -37
  119. package/dist/vega/p-315667f1.js +0 -1
  120. package/dist/vega/p-728b029a.entry.js +0 -1
  121. package/dist/vega/p-b6af0fc1.entry.js +0 -1
  122. package/dist/vega/p-e43c2a27.js +0 -1
@@ -0,0 +1,258 @@
1
+ import { generateUUID } from '../../../../../../utils/misc';
2
+ import { rgbToHex } from '../../../../../../utils/ui';
3
+ import { RTE_TEXT_COLORS } from '../../../../constants/constant';
4
+ import { ElementToDTOStrategy } from './element-to-dto-strategy.abstract';
5
+ /** Abstract class for block html element to RTE block dto */
6
+ export class BlockToRTEBlockStrategyAbstract extends ElementToDTOStrategy {
7
+ /**
8
+ * Generate child nodes of block element, this will inherit all annotations from parent to text node and
9
+ * flat the child nodes.
10
+ *
11
+ * Example:
12
+ * <li>
13
+ * <u><i>text1</i></u>
14
+ * <span style='font-weight: bold;'><span>text2</span></span>
15
+ * text3
16
+ * </li>
17
+ * will tranform to:
18
+ * <li>
19
+ * <span>text1</span> // with underline and italic annotations
20
+ * <span>text2</span> // with bold annotations
21
+ * <span>text3</span> // no annotations
22
+ * </li>
23
+ *
24
+ * @param {HTMLElement[]} elements - Child elements.
25
+ * @param {HTMLElement[]} annotations - Parent annotations.
26
+ * @returns {VegaRTETextNode[]} - Text node DTO.
27
+ */
28
+ generateChildNodes(elements, annotations = {}) {
29
+ const childNodes = [];
30
+ elements.forEach((child) => {
31
+ if (child.nodeType === Node.TEXT_NODE) {
32
+ if (this.isInvalidTextNode(child))
33
+ return;
34
+ childNodes.push({
35
+ id: generateUUID(),
36
+ type: 'text',
37
+ text: child.textContent,
38
+ annotations: annotations,
39
+ });
40
+ }
41
+ else {
42
+ childNodes.push(...this.generateChildNodes(Array.from(child.childNodes), Object.assign({}, annotations, this.generateTextNodeAnnotations(child))));
43
+ }
44
+ });
45
+ return childNodes;
46
+ }
47
+ /**
48
+ * Generate annotations map for block element.
49
+ *
50
+ * @param {HTMLElement} element - current element.
51
+ * @returns {VegaRTEBlockAnnotations} - Text block annotations.
52
+ */
53
+ generateBlockAnnotations(element) {
54
+ const annotations = {};
55
+ const textAlign = this.getTextAlign(element);
56
+ const indent = this.getIndent(element);
57
+ if (textAlign)
58
+ annotations.textAlign = textAlign;
59
+ if (indent)
60
+ annotations.indent = indent;
61
+ return annotations;
62
+ }
63
+ /**
64
+ * Check is a invalid text node.
65
+ *
66
+ * @param {HTMLElement} element - Current node element.
67
+ * @returns {boolean} - boolean.
68
+ */
69
+ isInvalidTextNode(element) {
70
+ if (element.nodeValue.includes('\t')) {
71
+ const value = element.nodeValue.replace(/\n|\t/gm, '');
72
+ if (value.length === 0)
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+ /**
78
+ * Generate annotations map for text node element.
79
+ *
80
+ * @param {HTMLElement} element - current element.
81
+ * @returns {VegaRTETextAnnotations | VegaRTECodeAnnotations} - Text node annotations.
82
+ */
83
+ generateTextNodeAnnotations(element) {
84
+ if (this.isCode(element))
85
+ return { code: true };
86
+ const annotations = {
87
+ bold: this.isBold(element),
88
+ italic: this.isItalic(element),
89
+ underline: this.isUnderline(element),
90
+ strikethrough: this.isStrikethrough(element),
91
+ };
92
+ const color = this.getColor(element);
93
+ const link = this.getLink(element);
94
+ if (color)
95
+ annotations.textColor = color;
96
+ if (link)
97
+ annotations.link = link;
98
+ return annotations;
99
+ }
100
+ /**
101
+ * Is code element.
102
+ *
103
+ * @param {HTMLElement} element - current element.
104
+ * @returns {boolean} - boolean.
105
+ */
106
+ isCode(element) {
107
+ return element.classList.contains('v-rte--code') || element.nodeName === 'CODE';
108
+ }
109
+ /**
110
+ * Is bold element.
111
+ *
112
+ * @param {HTMLElement} element - current element.
113
+ * @returns {boolean} - boolean.
114
+ */
115
+ isBold(element) {
116
+ return (element.nodeName === 'STRONG' ||
117
+ element.style.fontWeight === 'bold' ||
118
+ element.style.fontWeight === '700');
119
+ }
120
+ /**
121
+ * Is italic element.
122
+ *
123
+ * @param {HTMLElement} element - current element.
124
+ * @returns {boolean} - boolean.
125
+ */
126
+ isItalic(element) {
127
+ return element.nodeName === 'I' || element.style.fontStyle === 'italic' || element.nodeName === 'EM';
128
+ }
129
+ /**
130
+ * Is underline element.
131
+ *
132
+ * @param {HTMLElement} element - current element.
133
+ * @returns {boolean} - boolean.
134
+ */
135
+ isUnderline(element) {
136
+ return (element.style.textDecoration.includes('underline') ||
137
+ element.nodeName === 'U' ||
138
+ element.classList.contains('v-rte--underline'));
139
+ }
140
+ /**
141
+ * Is strikethrough element.
142
+ *
143
+ * @param {HTMLElement} element - current element.
144
+ * @returns {boolean} - boolean.
145
+ */
146
+ isStrikethrough(element) {
147
+ return (element.style.textDecoration.includes('line-through') ||
148
+ element.nodeName === 'S' ||
149
+ element.classList.contains('v-rte--strikethrough'));
150
+ }
151
+ /**
152
+ * Get current color of element.
153
+ *
154
+ * @param {HTMLElement} element - current element.
155
+ * @returns {Nullable<string>} - color.
156
+ */
157
+ getColor(element) {
158
+ var _a;
159
+ const color = element.style.color;
160
+ const hexColor = (_a = rgbToHex(color)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
161
+ if (hexColor) {
162
+ const colorSchema = RTE_TEXT_COLORS.find((schema) => schema.light === hexColor || schema.dark === hexColor);
163
+ if (colorSchema)
164
+ return colorSchema.key;
165
+ return null;
166
+ }
167
+ else {
168
+ for (const color of RTE_TEXT_COLORS) {
169
+ if (element.style.color.includes(color.key)) {
170
+ return color.key;
171
+ }
172
+ }
173
+ return null;
174
+ }
175
+ }
176
+ /**
177
+ * Get current link of element.
178
+ *
179
+ * @param {HTMLElement} element - current element.
180
+ * @returns {Nullable<VegaRTELink>} - link.
181
+ */
182
+ getLink(element) {
183
+ if (element.nodeName === 'A') {
184
+ return {
185
+ href: element.href,
186
+ groupKey: generateUUID(),
187
+ };
188
+ }
189
+ return null;
190
+ }
191
+ /**
192
+ * Get text align of current element.
193
+ *
194
+ * @param {HTMLElement} element - current element.
195
+ * @returns {Nullable<VegaRTEBlockAlignment>} - Text align.
196
+ */
197
+ getTextAlign(element) {
198
+ const classList = element.classList;
199
+ if (classList.contains(`v-rte--horizontal-alignment-left`)) {
200
+ return 'left';
201
+ }
202
+ else if (classList.contains(`v-rte--horizontal-alignment-center`)) {
203
+ return 'center';
204
+ }
205
+ else if (classList.contains(`v-rte--horizontal-alignment-right`)) {
206
+ return 'right';
207
+ }
208
+ else if (classList.contains(`v-rte--horizontal-alignment-justify`)) {
209
+ return 'justify';
210
+ }
211
+ const style = element.style;
212
+ switch (style.textAlign) {
213
+ case 'center':
214
+ return 'center';
215
+ case 'right':
216
+ return 'right';
217
+ case 'justify':
218
+ return 'justify';
219
+ case 'left':
220
+ return 'left';
221
+ default:
222
+ return null;
223
+ }
224
+ }
225
+ /**
226
+ * Get indent of current element.
227
+ *
228
+ * @param {HTMLElement} element - current element.
229
+ * @returns {Nullable<number>} - Indent.
230
+ */
231
+ getIndent(element) {
232
+ const style = element.style;
233
+ let marginLeft;
234
+ if (style.marginLeft) {
235
+ marginLeft = style.marginLeft;
236
+ }
237
+ else if (style.margin) {
238
+ const margins = style.margin.split(' ');
239
+ switch (margins.length) {
240
+ case 4:
241
+ marginLeft = margins[3];
242
+ break;
243
+ case 2:
244
+ case 3:
245
+ marginLeft = margins[1];
246
+ break;
247
+ default:
248
+ marginLeft = margins[0];
249
+ break;
250
+ }
251
+ }
252
+ else {
253
+ return null;
254
+ }
255
+ const marginLeftNumber = Number(marginLeft.replace('px', ''));
256
+ return marginLeftNumber && marginLeftNumber >= 0 ? Math.floor(marginLeftNumber / 16) : null;
257
+ }
258
+ }
@@ -0,0 +1,71 @@
1
+ import { generateUUID } from '../../../../../../utils/misc';
2
+ import { RTETextBlock } from '../../../../dto/blocks/text-block';
3
+ import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
4
+ /** Transform continue inline block elements to text block DTO */
5
+ export class ContinueInlineToRTETextBlockStrategy extends BlockToRTEBlockStrategyAbstract {
6
+ /**
7
+ * Can be handle.
8
+ *
9
+ * @param {HTMLElement[]} elementsArray - Current elements.
10
+ * @param {number} currentIndex - Current element index.
11
+ * @returns {number} - can be handled element count.
12
+ */
13
+ canHandle(elementsArray, currentIndex) {
14
+ let count = 0;
15
+ for (let i = currentIndex; i < elementsArray.length; i++) {
16
+ const element = elementsArray[i];
17
+ if (element.nodeType === Node.TEXT_NODE ||
18
+ (ContinueInlineToRTETextBlockStrategy.canHandleTags.includes(element.nodeName) &&
19
+ !(element.textContent === '' && element.querySelector('IMG')))) {
20
+ count++;
21
+ }
22
+ else {
23
+ break;
24
+ }
25
+ }
26
+ return count;
27
+ }
28
+ /**
29
+ * Parse to a text block.
30
+ *
31
+ * @param {HTMLElement[]} elementsArray - Current elements.
32
+ * @returns {Nullable<RTEContentBlock>} - Text block.
33
+ */
34
+ handle(elementsArray) {
35
+ const parent = elementsArray[0].parentElement;
36
+ const nodes = this.generateChildNodes(elementsArray);
37
+ if (nodes.length === 0)
38
+ return null;
39
+ return RTETextBlock.from({
40
+ id: generateUUID(),
41
+ type: 'paragraph',
42
+ nodes: nodes,
43
+ annotations: this.generateBlockAnnotations(parent),
44
+ });
45
+ }
46
+ /* istanbul ignore next */
47
+ /**
48
+ * Append child blocks.
49
+ */
50
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
51
+ appendChildBlocks() { }
52
+ /**
53
+ * Should continue process to child elements.
54
+ *
55
+ * @returns {boolean} - boolean.
56
+ */
57
+ shouldProceedToElementChildren() {
58
+ return false;
59
+ }
60
+ }
61
+ ContinueInlineToRTETextBlockStrategy.canHandleTags = [
62
+ 'SPAN',
63
+ 'STRONG',
64
+ 'CODE',
65
+ 'I',
66
+ 'EM',
67
+ 'S',
68
+ 'U',
69
+ 'A',
70
+ 'VEGA-RICH-TEXT-LINK-EDITOR',
71
+ ];
@@ -0,0 +1,70 @@
1
+ import { ElementToDTOStrategyOutput } from './element-to-dto-strategy.abstract';
2
+ import { ContinueInlineToRTETextBlockStrategy } from './continue-inline-to-rte-text-block-strategy';
3
+ import { UlToRTEListBlockStrategy } from './ul-to-rte-list-block-strategy';
4
+ import { LiToRTEListItemBlockStrategy } from './li-to-rte-list-item-block-strategy';
5
+ import { InlineBlockToRTETextBlockStrategy } from './inline-block-to-rte-text-block-strategy';
6
+ import { ImgToRTEImageBlockStrategy } from './img-to-rte-image-block-strategy';
7
+ import { VegaImageToRTEImageBlockStrategy } from './vega-image-to-rte-image-block-strategy';
8
+ import { OlToRTEListBlockStrategy } from './ol-to-rte-list-block-strategy';
9
+ import { SpanImageToRTEImageBlockStrategy } from './span-img-to-rte-image-block-strategy';
10
+ /** Element to DTO processor */
11
+ export class ElementToDtoStrategyProcessor {
12
+ constructor() {
13
+ this.elementStrategies = [
14
+ new UlToRTEListBlockStrategy(),
15
+ new OlToRTEListBlockStrategy(),
16
+ new LiToRTEListItemBlockStrategy(),
17
+ new InlineBlockToRTETextBlockStrategy(),
18
+ new ImgToRTEImageBlockStrategy(),
19
+ new VegaImageToRTEImageBlockStrategy(),
20
+ new SpanImageToRTEImageBlockStrategy(),
21
+ new ContinueInlineToRTETextBlockStrategy(),
22
+ ];
23
+ }
24
+ /**
25
+ * Transform process.
26
+ *
27
+ * @param {HTMLElement[]} elements - Current elements.
28
+ * @returns {ElementToDTOStrategyOutput[]} - outputs.
29
+ */
30
+ process(elements) {
31
+ const outputs = [];
32
+ for (let i = 0; i < elements.length; i++) {
33
+ if (this.isInvalidElement(elements[i]))
34
+ continue;
35
+ let canHandledCount = 0;
36
+ for (const strategy of this.elementStrategies) {
37
+ canHandledCount = strategy.canHandle(elements, i);
38
+ if (canHandledCount > 0) {
39
+ const handledElements = elements.slice(i, i + canHandledCount);
40
+ const output = new ElementToDTOStrategyOutput(strategy, handledElements);
41
+ if (canHandledCount === 1 && strategy.shouldProceedToElementChildren()) {
42
+ output.setChildrenOutput(this.process(Array.from(handledElements[0].childNodes)));
43
+ }
44
+ outputs.push(output);
45
+ i += canHandledCount - 1;
46
+ break;
47
+ }
48
+ }
49
+ if (canHandledCount === 0 && i < elements.length) {
50
+ const elementChildren = Array.from(elements[i].childNodes);
51
+ const childrenOutputs = this.process(Array.from(elementChildren));
52
+ if (childrenOutputs.length > 0) {
53
+ outputs.push(...childrenOutputs);
54
+ }
55
+ }
56
+ }
57
+ return outputs;
58
+ }
59
+ /**
60
+ * Checks if the given element is valid to parse.
61
+ *
62
+ * @param {HTMLElement} element - The pasted element.
63
+ * @returns {boolean} Is valid
64
+ */
65
+ isInvalidElement(element) {
66
+ if (element.nodeType === Node.COMMENT_NODE)
67
+ return true;
68
+ return ['META', 'BUTTON', 'STYLE'].includes(element.nodeName);
69
+ }
70
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Abstract class to define strategies for processing HTML elements
3
+ */
4
+ export class ElementToDTOStrategy {
5
+ }
6
+ /**
7
+ * Class to represent the output of a strategy applied to HTML elements
8
+ */
9
+ export class ElementToDTOStrategyOutput {
10
+ constructor(currentStrategy, currentElements) {
11
+ this.childrenOutput = [];
12
+ this.currentStrategy = currentStrategy;
13
+ this.currentElements = currentElements;
14
+ }
15
+ /**
16
+ * Set children output.
17
+ *
18
+ * @param {ElementToDTOStrategyOutput[]} childrenOutput - children outputs.
19
+ */
20
+ setChildrenOutput(childrenOutput) {
21
+ this.childrenOutput = childrenOutput;
22
+ }
23
+ /**
24
+ * Transform current output and children output to DTO
25
+ *
26
+ * @returns {RTEContentBlock} - DTO.
27
+ */
28
+ toDto() {
29
+ const currentBlock = this.currentStrategy.handle(this.currentElements);
30
+ if (this.childrenOutput.length > 0 && currentBlock) {
31
+ this.currentStrategy.appendChildBlocks(currentBlock, this.childrenOutput
32
+ .map((childOutput) => childOutput.toDto())
33
+ .filter(Boolean));
34
+ }
35
+ return currentBlock;
36
+ }
37
+ }
@@ -0,0 +1,55 @@
1
+ import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
2
+ import { generateUUID } from '../../../../../../utils/misc';
3
+ import { RTEImageBlock } from '../../../../dto/blocks/image-block';
4
+ /** Transform img element to image block DTO */
5
+ export class ImgToRTEImageBlockStrategy extends BlockToRTEBlockStrategyAbstract {
6
+ /**
7
+ * Can be handle.
8
+ *
9
+ * @param {HTMLElement[]} elementsArray - Current elements.
10
+ * @param {number} currentIndex - Current element index.
11
+ * @returns {number} - can be handled element count.
12
+ */
13
+ canHandle(elementsArray, currentIndex) {
14
+ return elementsArray[currentIndex].tagName === 'IMG' ? 1 : 0;
15
+ }
16
+ /**
17
+ * Parse to a image block.
18
+ *
19
+ * @param {HTMLElement[]} elementsArray - Current elements.
20
+ * @returns {Nullable<RTEContentBlock>} - Image block.
21
+ */
22
+ handle(elementsArray) {
23
+ const element = elementsArray[0];
24
+ return RTEImageBlock.from({
25
+ id: generateUUID(),
26
+ type: 'image',
27
+ nodes: [
28
+ {
29
+ id: generateUUID(),
30
+ type: 'image',
31
+ url: element.src,
32
+ annotations: {
33
+ size: 'md',
34
+ alt: element.alt,
35
+ },
36
+ },
37
+ ],
38
+ annotations: this.generateBlockAnnotations(element),
39
+ });
40
+ }
41
+ /* istanbul ignore next */
42
+ /**
43
+ * Append child blocks.
44
+ */
45
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
46
+ appendChildBlocks() { }
47
+ /**
48
+ * Should continue process to child elements.
49
+ *
50
+ * @returns {boolean} - boolean.
51
+ */
52
+ shouldProceedToElementChildren() {
53
+ return false;
54
+ }
55
+ }
@@ -0,0 +1,85 @@
1
+ import { generateUUID } from '../../../../../../utils/misc';
2
+ import { RTETextBlock } from '../../../../dto/blocks/text-block';
3
+ import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
4
+ /** Transform inline block element to text block DTO */
5
+ export class InlineBlockToRTETextBlockStrategy extends BlockToRTEBlockStrategyAbstract {
6
+ /**
7
+ * Can be handle.
8
+ *
9
+ * @param {HTMLElement[]} elementsArray - Current elements.
10
+ * @param {number} currentIndex - Current element index.
11
+ * @returns {number} - can be handled element count.
12
+ */
13
+ canHandle(elementsArray, currentIndex) {
14
+ return ['heading-1', 'heading-2', 'heading-3', 'title', 'subtitle'].includes(this.getElementType(elementsArray[currentIndex]))
15
+ ? 1
16
+ : 0;
17
+ }
18
+ /**
19
+ * Parse to a text block.
20
+ *
21
+ * @param {HTMLElement[]} elementsArray - Current elements.
22
+ * @returns {Nullable<RTEContentBlock>} - Text block.
23
+ */
24
+ handle(elementsArray) {
25
+ const nodes = this.generateChildNodes(elementsArray);
26
+ if (nodes.length === 0)
27
+ return null;
28
+ return RTETextBlock.from({
29
+ id: generateUUID(),
30
+ type: this.getElementType(elementsArray[0]),
31
+ nodes: nodes,
32
+ annotations: Object.assign(Object.assign({}, this.generateBlockAnnotations(elementsArray[0])), { textStyle: this.getElementType(elementsArray[0]) }),
33
+ });
34
+ }
35
+ /* istanbul ignore next */
36
+ /**
37
+ * Append child blocks.
38
+ */
39
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
40
+ appendChildBlocks() { }
41
+ /**
42
+ * Should continue process to child elements.
43
+ *
44
+ * @returns {boolean} - boolean.
45
+ */
46
+ shouldProceedToElementChildren() {
47
+ return false;
48
+ }
49
+ /**
50
+ * Get node type of element.
51
+ *
52
+ * @param {HTMLElement} element - element.
53
+ * @returns {string} - node type.
54
+ */
55
+ getElementType(element) {
56
+ var _a;
57
+ if (element.nodeType !== Node.TEXT_NODE && element.hasAttribute('data-type')) {
58
+ return element.getAttribute('data-type');
59
+ }
60
+ switch ((_a = element.style) === null || _a === void 0 ? void 0 : _a.fontSize) {
61
+ case '36px':
62
+ return 'title';
63
+ case '28px':
64
+ return 'subtitle';
65
+ case '22px':
66
+ return 'heading-1';
67
+ case '20px':
68
+ return 'heading-2';
69
+ case '18px':
70
+ return 'heading-3';
71
+ default:
72
+ break;
73
+ }
74
+ switch (element.nodeName) {
75
+ case 'H1':
76
+ return 'heading-1';
77
+ case 'H2':
78
+ return 'heading-2';
79
+ case 'H3':
80
+ return 'heading-3';
81
+ default:
82
+ return '';
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,49 @@
1
+ import { generateUUID } from '../../../../../../utils/misc';
2
+ import { RTEListItemBlock } from '../../../../dto/blocks/list-item-block';
3
+ import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
4
+ /** Transform li element to list item block DTO */
5
+ export class LiToRTEListItemBlockStrategy extends BlockToRTEBlockStrategyAbstract {
6
+ /**
7
+ * Can be handle.
8
+ *
9
+ * @param {HTMLElement[]} elementsArray - Current elements.
10
+ * @param {number} currentIndex - Current element index.
11
+ * @returns {number} - can be handled element count.
12
+ */
13
+ canHandle(elementsArray, currentIndex) {
14
+ return elementsArray[currentIndex].tagName === 'LI' ? 1 : 0;
15
+ }
16
+ /**
17
+ * Parse to a list item block.
18
+ *
19
+ * @param {HTMLElement[]} elementsArray - Current elements.
20
+ * @returns {Nullable<RTEContentBlock>} - List item block.
21
+ */
22
+ handle(elementsArray) {
23
+ if (elementsArray[0].childNodes.length === 0)
24
+ return null;
25
+ return RTEListItemBlock.from({
26
+ id: generateUUID(),
27
+ type: 'list-item',
28
+ nodes: this.generateChildNodes(Array.from(elementsArray[0].childNodes).filter((item) => !['UL', 'OL'].includes(item.nodeName))),
29
+ annotations: this.generateBlockAnnotations(elementsArray[0]),
30
+ });
31
+ }
32
+ /**
33
+ * Append child list blocks to current list item block.
34
+ *
35
+ * @param {RTEListBlock} currentBlock - Current list item block.
36
+ * @param {RTEListItemBlock[]} childBlocks - Current list blocks.
37
+ */
38
+ appendChildBlocks(currentBlock, childBlocks) {
39
+ currentBlock.children = childBlocks.filter((block) => ['bullet-list', 'number-list'].includes(block.type));
40
+ }
41
+ /**
42
+ * Should continue process to child elements.
43
+ *
44
+ * @returns {boolean} - boolean.
45
+ */
46
+ shouldProceedToElementChildren() {
47
+ return true;
48
+ }
49
+ }
@@ -0,0 +1,50 @@
1
+ import { generateUUID } from '../../../../../../utils/misc';
2
+ import { RTEListBlock } from '../../../../dto/blocks/list-block';
3
+ import { BlockToRTEBlockStrategyAbstract } from './block-to-rte-block-strategy.abstract';
4
+ /** Transform ol element to list block DTO */
5
+ export class OlToRTEListBlockStrategy extends BlockToRTEBlockStrategyAbstract {
6
+ /**
7
+ * Can be handle.
8
+ *
9
+ * @param {HTMLElement[]} elementsArray - Current elements.
10
+ * @param {number} currentIndex - Current element index.
11
+ * @returns {number} - can be handled element count.
12
+ */
13
+ canHandle(elementsArray, currentIndex) {
14
+ return elementsArray[currentIndex].tagName === 'OL' ? 1 : 0;
15
+ }
16
+ /**
17
+ * Parse to a number list block.
18
+ *
19
+ * @param {HTMLElement[]} elementsArray - Current elements.
20
+ * @returns {Nullable<RTEContentBlock>} - Number list block.
21
+ */
22
+ handle(elementsArray) {
23
+ if (elementsArray[0].childNodes.length === 0)
24
+ return null;
25
+ return RTEListBlock.from({
26
+ id: generateUUID(),
27
+ type: 'number-list',
28
+ blocks: [],
29
+ annotations: this.generateBlockAnnotations(elementsArray[0]),
30
+ });
31
+ }
32
+ /**
33
+ * Append child list item blocks to current list block.
34
+ *
35
+ * @param {RTEListBlock} currentBlock - Current list block.
36
+ * @param {RTEListItemBlock[]} childBlocks - Current list item blocks.
37
+ */
38
+ appendChildBlocks(currentBlock, childBlocks) {
39
+ currentBlock.blocks = childBlocks;
40
+ childBlocks.forEach((block) => (block.parent = currentBlock));
41
+ }
42
+ /**
43
+ * Should continue process to child elements.
44
+ *
45
+ * @returns {boolean} - boolean.
46
+ */
47
+ shouldProceedToElementChildren() {
48
+ return true;
49
+ }
50
+ }