@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
@@ -5,11 +5,11 @@ import { c as createEnterKeyHandlerToTriggerClick } from './accessibility-e5fd0f
5
5
  import { C as ChangeManager } from './change-manager-8f5b72c2.js';
6
6
  import { d as domNodeSubjectFactory, D as DomNodeSubjectObserverFactory, c as VegaDropdownClick, V as VegaChange, O as Observer, Q as VegaImageInserted, b as VegaClick, M as VegaPopoverShow, N as VegaPopoverHide } from './dom-node-subject-observer-factory-80358591.js';
7
7
  import { a as VegaInternalComponentDidRender, b as VegaInternalRichTextEditorSelectionRangeChange, V as VegaInternalRichTextEditorFlushChanges, o as VegaInternalRichTextImageClick, p as VegaInternalRichTextImageDeleteButtonClicked, k as VegaInternalPopoverUpdateTarget } from './vega-internal-event-id-4af5c6e9.js';
8
- import { a as ToolbarButtonSlimmer, T as TextColorToolbarButtonSlimmer } from './text-color-toolbar-button-slimmer-d0255b98.js';
8
+ import { a as ToolbarButtonSlimmer, T as TextColorToolbarButtonSlimmer } from './text-color-toolbar-button-slimmer-b2270b64.js';
9
9
  import { V as VegaInternalIconManager } from './internal-icon-manager-7fc7535a.js';
10
- import { B as BoldAnnotationAction, R as RTETextBlock, T as TextStyleAnnotationAction, a as TextStyleAnnotation, I as IndentAnnotation, b as RTEImageNode, c as RTEListItemBlock, H as HorizontalAlignmentAnnotation, V as VegaRTEContent, d as RemoveChildAction, A as AppendChildNodesAction, e as InsertBlocksBeforeAction, M as MergeTwoBlocksNodesAction, S as SplitBlockWithNodeAction, f as ReplaceChildNodesAction, g as RTEImageBlock, h as RTEListBlock, i as InsertBlocksAfterAction, j as ImageAnnotationAction } from './content-state-acf55eb0.js';
10
+ import { B as BoldAnnotationAction, R as RTETextBlock, T as TextStyleAnnotationAction, a as TextStyleAnnotation, I as IndentAnnotation, b as RTEImageNode, c as RTEListItemBlock, H as HorizontalAlignmentAnnotation, V as VegaRTEContent, d as RemoveChildAction, A as AppendChildNodesAction, e as InsertBlocksBeforeAction, M as MergeTwoBlocksNodesAction, S as SplitBlockWithNodeAction, f as ReplaceChildNodesAction, g as RTEListBlock, h as RTEImageBlock, i as InsertBlocksAfterAction, j as ImageAnnotationAction } from './content-state-4b036bf1.js';
11
11
  import { a as NodeAnnotationTypeEnum, M as ModifyContentAction, b as ModifyContentActionType, R as RTENode, s as stateEntityRenderingRegistry, I as InternalAnnotationTypeEnum, V as VegaThemeManager } from './node.abstract-93746055.js';
12
- import { R as RTETextNode, T as TextSplittableAction, I as ItalicAnnotation, e as UnderlineAnnotation, B as BoldAnnotation, C as ClearFormattingAnnotationAction, f as CodeAnnotationAction, g as StrikethroughAnnotation, A as AnnotationAction, h as SelectionRangeAnnotation, L as LinkAnnotationAction, b as waitForComponentDidRender, Z as ZERO_WIDTH_SPACE, U as UpdateTextAction, i as TextNodeRenderingRegistry } from './text-node-6f7d736c.js';
12
+ import { R as RTETextNode, T as TextSplittableAction, I as ItalicAnnotation, e as UnderlineAnnotation, B as BoldAnnotation, C as ClearFormattingAnnotationAction, f as CodeAnnotationAction, g as StrikethroughAnnotation, A as AnnotationAction, h as SelectionRangeAnnotation, L as LinkAnnotationAction, b as waitForComponentDidRender, Z as ZERO_WIDTH_SPACE, U as UpdateTextAction, d as RTE_TEXT_COLORS, i as TextNodeRenderingRegistry } from './text-node-a652ca87.js';
13
13
  import { e as BlockAnnotationTypeEnum } from './block-annotation.abstract-b0554e2b.js';
14
14
  import { g as generateUUID } from './create-public-api-runtime-metrics-slimmer-14cb4599.js';
15
15
  import { F as FormFieldControllerSlimmer } from './form-field-controller-slimmer-de5fe574.js';
@@ -17,7 +17,7 @@ import { c as createEventEmitSlimmer } from './event-emit-slimmer-c03cf145.js';
17
17
  import { c as createSubStateNotifySlimmer } from './sub-state-notify-slimmer-6e97a58a.js';
18
18
  import { d as debounce } from './timer-9321173b.js';
19
19
  import { S as SynchronizeTaskQueue } from './synchronize-task-queue-ac8acc3b.js';
20
- import { f as findParent } from './ui-5600b48f.js';
20
+ import { f as findParent, r as rgbToHex } from './ui-5600b48f.js';
21
21
  import { b as FORM_ELEMENT_VALUE_CHANGE, D as DARK_MODE_CHANGE } from './static-subject-title-e06a3840.js';
22
22
  import './vega-env-manager-8f8dc473.js';
23
23
  import './feature-flag-controller-dfde0cfa.js';
@@ -2906,446 +2906,530 @@ class DeleteContentHandler extends BaseHandler {
2906
2906
  }
2907
2907
 
2908
2908
  /**
2909
- * Abstract class of element to DTO handler
2909
+ * Abstract class to define strategies for processing HTML elements
2910
2910
  */
2911
- class ElementToDTOHandlerAbstract {
2912
- /**
2913
- * At new of handler, We need to inherit the style of the parent element
2914
- * and clone an empty element so that the child elements can be appended.
2915
- *
2916
- * @param {HTMLElement} element - Current element.
2917
- */
2918
- constructor(element) {
2919
- this.setEntityElementStyle(element);
2920
- this.setElement(element);
2911
+ class ElementToDTOStrategy {
2912
+ }
2913
+ /**
2914
+ * Class to represent the output of a strategy applied to HTML elements
2915
+ */
2916
+ class ElementToDTOStrategyOutput {
2917
+ constructor(currentStrategy, currentElements) {
2918
+ this.childrenOutput = [];
2919
+ this.currentStrategy = currentStrategy;
2920
+ this.currentElements = currentElements;
2921
2921
  }
2922
- /* istanbul ignore next */
2923
- // eslint-disable-next-line jsdoc/require-returns-check
2924
2922
  /**
2925
- * Can be handle, the class inherit this class should implement it.
2923
+ * Set children output.
2926
2924
  *
2927
- * @param {HTMLElement} element - Current element.
2928
- * @returns {boolean} Can be handle.
2925
+ * @param {ElementToDTOStrategyOutput[]} childrenOutput - children outputs.
2929
2926
  */
2930
- static canHandle(element) {
2931
- throw new Error(`Method not implemented! ${element}`);
2927
+ setChildrenOutput(childrenOutput) {
2928
+ this.childrenOutput = childrenOutput;
2932
2929
  }
2933
2930
  /**
2934
- * Transform current text block to a DTO.
2931
+ * Transform current output and children output to DTO
2935
2932
  *
2936
- * @returns {RTETextBlock} Current text block.
2937
- */
2938
- static currentTextBlockElementToDTO() {
2939
- const element = this.getCurrentTextBlockElement();
2940
- const firstNode = element.firstChild;
2941
- if (firstNode && firstNode.nodeName === 'SPAN' && firstNode.textContent === '\n') {
2942
- firstNode.remove();
2943
- }
2944
- if (element.childNodes.length > 0) {
2945
- const block = RTETextBlock.fromHTML(element, 'paragraph');
2946
- element.innerHTML = '';
2947
- return block;
2933
+ * @returns {RTEContentBlock} - DTO.
2934
+ */
2935
+ toDto() {
2936
+ const currentBlock = this.currentStrategy.handle(this.currentElements);
2937
+ if (this.childrenOutput.length > 0 && currentBlock) {
2938
+ this.currentStrategy.appendChildBlocks(currentBlock, this.childrenOutput
2939
+ .map((childOutput) => childOutput.toDto())
2940
+ .filter(Boolean));
2948
2941
  }
2949
- return null;
2942
+ return currentBlock;
2950
2943
  }
2944
+ }
2945
+
2946
+ /** Abstract class for block html element to RTE block dto */
2947
+ class BlockToRTEBlockStrategyAbstract extends ElementToDTOStrategy {
2951
2948
  /**
2952
- * Get current text block element.
2949
+ * Generate child nodes of block element, this will inherit all annotations from parent to text node and
2950
+ * flat the child nodes.
2953
2951
  *
2954
- * @returns {HTMLDivElement} - Current text block element.
2955
- */
2956
- static getCurrentTextBlockElement() {
2957
- return ElementToDTOHandlerAbstract.currentTextBlockElement;
2952
+ * Example:
2953
+ * <li>
2954
+ * <u><i>text1</i></u>
2955
+ * <span style='font-weight: bold;'><span>text2</span></span>
2956
+ * text3
2957
+ * </li>
2958
+ * will tranform to:
2959
+ * <li>
2960
+ * <span>text1</span> // with underline and italic annotations
2961
+ * <span>text2</span> // with bold annotations
2962
+ * <span>text3</span> // no annotations
2963
+ * </li>
2964
+ *
2965
+ * @param {HTMLElement[]} elements - Child elements.
2966
+ * @param {HTMLElement[]} annotations - Parent annotations.
2967
+ * @returns {VegaRTETextNode[]} - Text node DTO.
2968
+ */
2969
+ generateChildNodes(elements, annotations = {}) {
2970
+ const childNodes = [];
2971
+ elements.forEach((child) => {
2972
+ if (child.nodeType === Node.TEXT_NODE) {
2973
+ if (this.isInvalidTextNode(child))
2974
+ return;
2975
+ childNodes.push({
2976
+ id: generateUUID(),
2977
+ type: 'text',
2978
+ text: child.textContent,
2979
+ annotations: annotations,
2980
+ });
2981
+ }
2982
+ else {
2983
+ childNodes.push(...this.generateChildNodes(Array.from(child.childNodes), Object.assign({}, annotations, this.generateTextNodeAnnotations(child))));
2984
+ }
2985
+ });
2986
+ return childNodes;
2958
2987
  }
2959
2988
  /**
2960
- * While it a empty block. we should use new line span instead this block.
2989
+ * Generate annotations map for block element.
2961
2990
  *
2962
- * @param {HTMLElement} blockElement - Current block element.
2963
- * @returns {boolean} - is handled.
2991
+ * @param {HTMLElement} element - current element.
2992
+ * @returns {VegaRTEBlockAnnotations} - Text block annotations.
2964
2993
  */
2965
- handleEmptyBlock(blockElement) {
2966
- if (this.currentVirtualElement.childNodes.length === 0) {
2967
- (blockElement || ElementToDTOHandlerAbstract.getCurrentTextBlockElement()).append(this.createNewLineSpan());
2968
- return true;
2969
- }
2970
- return false;
2994
+ generateBlockAnnotations(element) {
2995
+ const annotations = {};
2996
+ const textAlign = this.getTextAlign(element);
2997
+ const indent = this.getIndent(element);
2998
+ if (textAlign)
2999
+ annotations.textAlign = textAlign;
3000
+ if (indent)
3001
+ annotations.indent = indent;
3002
+ return annotations;
2971
3003
  }
2972
3004
  /**
2973
- * Inherit style of parent.
3005
+ * Check is a invalid text node.
2974
3006
  *
2975
- * @param {HTMLElement} element - Current element.
3007
+ * @param {HTMLElement} element - Current node element.
3008
+ * @returns {boolean} - boolean.
2976
3009
  */
2977
- setEntityElementStyle(element) {
2978
- if (element.nodeType === Node.TEXT_NODE)
2979
- return;
2980
- let currentStyle = element.getAttribute('style') || '';
2981
- const currentClass = element.classList;
2982
- const parent = element.parentElement;
2983
- const parentStyle = parent.getAttribute('style') || '';
2984
- const parentClass = parent.classList;
2985
- switch (element.nodeName) {
2986
- case 'CODE':
2987
- currentClass.add('v-rte--code');
2988
- break;
2989
- case 'STRONG':
2990
- currentStyle += 'font-weight: bold; ';
2991
- break;
2992
- case 'I':
2993
- case 'EM':
2994
- currentStyle += 'font-style: italic; ';
2995
- break;
2996
- case 'S':
2997
- currentClass.add('v-rte--strikethrough');
2998
- break;
2999
- case 'U':
3000
- currentClass.add('v-rte--underline');
3001
- break;
3010
+ isInvalidTextNode(element) {
3011
+ if (element.nodeValue.includes('\t')) {
3012
+ const value = element.nodeValue.replace(/\n|\t/gm, '');
3013
+ if (value.length === 0)
3014
+ return true;
3002
3015
  }
3003
- element.setAttribute('style', parentStyle + currentStyle);
3004
- element.classList.add(...Array.from(parentClass));
3016
+ return false;
3005
3017
  }
3006
3018
  /**
3007
- * Set current element.
3008
- * while element is a text node, we should wrap it and inherit it style
3009
- * otherwise, we should clone it and clear content.
3019
+ * Generate annotations map for text node element.
3010
3020
  *
3011
- * @param {HTMLElement} element - Current element.
3012
- */
3013
- setElement(element) {
3014
- this.currentEntityElement = element;
3015
- if (element.nodeType === Node.TEXT_NODE) {
3016
- const wrapper = document.createElement('span');
3017
- wrapper.setAttribute('style', element.parentElement.getAttribute('style'));
3018
- wrapper.setAttribute('class', element.parentElement.getAttribute('class'));
3019
- wrapper.append(element);
3020
- this.currentVirtualElement = wrapper;
3021
- }
3022
- else {
3023
- const elementClone = element.cloneNode(true);
3024
- elementClone.innerHTML = '';
3025
- this.currentVirtualElement = elementClone;
3026
- }
3021
+ * @param {HTMLElement} element - current element.
3022
+ * @returns {VegaRTETextAnnotations | VegaRTECodeAnnotations} - Text node annotations.
3023
+ */
3024
+ generateTextNodeAnnotations(element) {
3025
+ if (this.isCode(element))
3026
+ return { code: true };
3027
+ const annotations = {
3028
+ bold: this.isBold(element),
3029
+ italic: this.isItalic(element),
3030
+ underline: this.isUnderline(element),
3031
+ strikethrough: this.isStrikethrough(element),
3032
+ };
3033
+ const color = this.getColor(element);
3034
+ const link = this.getLink(element);
3035
+ if (color)
3036
+ annotations.textColor = color;
3037
+ if (link)
3038
+ annotations.link = link;
3039
+ return annotations;
3027
3040
  }
3028
3041
  /**
3029
- * Create a new line span.
3042
+ * Is code element.
3030
3043
  *
3031
- * @returns {HTMLElement} - new line span.
3044
+ * @param {HTMLElement} element - current element.
3045
+ * @returns {boolean} - boolean.
3032
3046
  */
3033
- createNewLineSpan() {
3034
- const span = document.createElement('span');
3035
- span.append('\n');
3036
- return span;
3047
+ isCode(element) {
3048
+ return element.classList.contains('v-rte--code') || element.nodeName === 'CODE';
3037
3049
  }
3038
- }
3039
- ElementToDTOHandlerAbstract.currentTextBlockElement = document.createElement('div');
3040
-
3041
- /**
3042
- * Transform image element to DTO.
3043
- */
3044
- class ImageToDTOHandler extends ElementToDTOHandlerAbstract {
3045
3050
  /**
3046
- * Can be transform.
3051
+ * Is bold element.
3047
3052
  *
3048
- * @param {HTMLElement} element - An pasted element.
3049
- * @returns {boolean} Result.
3053
+ * @param {HTMLElement} element - current element.
3054
+ * @returns {boolean} - boolean.
3050
3055
  */
3051
- static canHandle(element) {
3052
- return (element.nodeType === Node.ELEMENT_NODE &&
3053
- (element.nodeName === 'IMG' || element.querySelector('vega-rich-text-image-editor') !== null));
3056
+ isBold(element) {
3057
+ return (element.nodeName === 'STRONG' ||
3058
+ element.style.fontWeight === 'bold' ||
3059
+ element.style.fontWeight === '700');
3054
3060
  }
3055
3061
  /**
3056
- * Special the child elements of current.
3062
+ * Is italic element.
3057
3063
  *
3058
- * @returns {HTMLElement[]} - child elements.
3064
+ * @param {HTMLElement} element - current element.
3065
+ * @returns {boolean} - boolean.
3059
3066
  */
3060
- childElements() {
3061
- return [];
3067
+ isItalic(element) {
3068
+ return element.nodeName === 'I' || element.style.fontStyle === 'italic' || element.nodeName === 'EM';
3062
3069
  }
3063
3070
  /**
3064
- * Transform element to DTO.
3065
- * When blockElement is exist, it means that the current element is a child node,
3066
- * and we need to wait for its root block to be converted into a dto.
3067
- * Otherwise, the current node is the root node, and we can directly convert it.
3071
+ * Is underline element.
3068
3072
  *
3069
- * @returns {RTEContentBlock[]} - Block DTO.
3073
+ * @param {HTMLElement} element - current element.
3074
+ * @returns {boolean} - boolean.
3070
3075
  */
3071
- handle() {
3072
- return [
3073
- ElementToDTOHandlerAbstract.currentTextBlockElementToDTO(),
3074
- RTEImageBlock.fromHTML(this.currentEntityElement),
3075
- ];
3076
+ isUnderline(element) {
3077
+ return (element.style.textDecoration.includes('underline') ||
3078
+ element.nodeName === 'U' ||
3079
+ element.classList.contains('v-rte--underline'));
3076
3080
  }
3077
3081
  /**
3078
- * Get the block element for child nodes
3082
+ * Is strikethrough element.
3079
3083
  *
3080
- * @returns {HTMLElement} - Block element for child nodes.
3084
+ * @param {HTMLElement} element - current element.
3085
+ * @returns {boolean} - boolean.
3081
3086
  */
3082
- getNextBlockElement() {
3083
- return this.currentVirtualElement;
3087
+ isStrikethrough(element) {
3088
+ return (element.style.textDecoration.includes('line-through') ||
3089
+ element.nodeName === 'S' ||
3090
+ element.classList.contains('v-rte--strikethrough'));
3084
3091
  }
3085
- }
3086
-
3087
- /**
3088
- * Transform link element to DTO.
3089
- */
3090
- class InlineBlockToDTOHandler extends ElementToDTOHandlerAbstract {
3091
3092
  /**
3092
- * Can be transform.
3093
+ * Get current color of element.
3093
3094
  *
3094
- * @returns {boolean} Result.
3095
+ * @param {HTMLElement} element - current element.
3096
+ * @returns {Nullable<string>} - color.
3095
3097
  */
3096
- static canHandle() {
3097
- return true;
3098
+ getColor(element) {
3099
+ var _a;
3100
+ const color = element.style.color;
3101
+ const hexColor = (_a = rgbToHex(color)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
3102
+ if (hexColor) {
3103
+ const colorSchema = RTE_TEXT_COLORS.find((schema) => schema.light === hexColor || schema.dark === hexColor);
3104
+ if (colorSchema)
3105
+ return colorSchema.key;
3106
+ return null;
3107
+ }
3108
+ else {
3109
+ for (const color of RTE_TEXT_COLORS) {
3110
+ if (element.style.color.includes(color.key)) {
3111
+ return color.key;
3112
+ }
3113
+ }
3114
+ return null;
3115
+ }
3098
3116
  }
3099
3117
  /**
3100
- * Special the child elements of current.
3118
+ * Get current link of element.
3101
3119
  *
3102
- * @returns {HTMLElement[]} - child elements.
3103
- */
3104
- childElements() {
3105
- return Array.from(this.currentEntityElement.childNodes);
3120
+ * @param {HTMLElement} element - current element.
3121
+ * @returns {Nullable<VegaRTELink>} - link.
3122
+ */
3123
+ getLink(element) {
3124
+ if (element.nodeName === 'A') {
3125
+ return {
3126
+ href: element.href,
3127
+ groupKey: generateUUID(),
3128
+ };
3129
+ }
3130
+ return null;
3106
3131
  }
3107
3132
  /**
3108
- * The inline block is a child element, and there is no need to convert it to a dto here
3133
+ * Get text align of current element.
3109
3134
  *
3110
- * @returns {RTEContentBlock[]} - Empty dto.
3135
+ * @param {HTMLElement} element - current element.
3136
+ * @returns {Nullable<VegaRTEBlockAlignment>} - Text align.
3111
3137
  */
3112
- handle() {
3113
- return [];
3138
+ getTextAlign(element) {
3139
+ const classList = element.classList;
3140
+ if (classList.contains(`v-rte--horizontal-alignment-left`)) {
3141
+ return 'left';
3142
+ }
3143
+ else if (classList.contains(`v-rte--horizontal-alignment-center`)) {
3144
+ return 'center';
3145
+ }
3146
+ else if (classList.contains(`v-rte--horizontal-alignment-right`)) {
3147
+ return 'right';
3148
+ }
3149
+ else if (classList.contains(`v-rte--horizontal-alignment-justify`)) {
3150
+ return 'justify';
3151
+ }
3152
+ const style = element.style;
3153
+ switch (style.textAlign) {
3154
+ case 'center':
3155
+ return 'center';
3156
+ case 'right':
3157
+ return 'right';
3158
+ case 'justify':
3159
+ return 'justify';
3160
+ case 'left':
3161
+ return 'left';
3162
+ default:
3163
+ return null;
3164
+ }
3114
3165
  }
3115
3166
  /**
3116
- * Get the block element for child nodes
3167
+ * Get indent of current element.
3117
3168
  *
3118
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3119
- * @returns {Nullable<HTMLElement>} - blockElement.
3120
- */
3121
- getNextBlockElement(blockElement) {
3122
- return blockElement;
3169
+ * @param {HTMLElement} element - current element.
3170
+ * @returns {Nullable<number>} - Indent.
3171
+ */
3172
+ getIndent(element) {
3173
+ const style = element.style;
3174
+ let marginLeft;
3175
+ if (style.marginLeft) {
3176
+ marginLeft = style.marginLeft;
3177
+ }
3178
+ else if (style.margin) {
3179
+ const margins = style.margin.split(' ');
3180
+ switch (margins.length) {
3181
+ case 4:
3182
+ marginLeft = margins[3];
3183
+ break;
3184
+ case 2:
3185
+ case 3:
3186
+ marginLeft = margins[1];
3187
+ break;
3188
+ default:
3189
+ marginLeft = margins[0];
3190
+ break;
3191
+ }
3192
+ }
3193
+ else {
3194
+ return null;
3195
+ }
3196
+ const marginLeftNumber = Number(marginLeft.replace('px', ''));
3197
+ return marginLeftNumber && marginLeftNumber >= 0 ? Math.floor(marginLeftNumber / 16) : null;
3123
3198
  }
3124
3199
  }
3125
3200
 
3126
- /**
3127
- * Transform link element to DTO.
3128
- */
3129
- class LinkToDTOHandler extends ElementToDTOHandlerAbstract {
3130
- constructor(element) {
3131
- super(element);
3132
- }
3133
- /**
3134
- * Can be transform.
3135
- *
3136
- * @param {HTMLElement} element - An pasted element.
3137
- * @returns {boolean} Result.
3138
- */
3139
- static canHandle(element) {
3140
- return ['A'].includes(element.nodeName);
3141
- }
3201
+ /** Transform continue inline block elements to text block DTO */
3202
+ class ContinueInlineToRTETextBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3142
3203
  /**
3143
- * Special the child elements of current.
3204
+ * Can be handle.
3144
3205
  *
3145
- * @returns {HTMLElement[]} - child elements.
3146
- */
3147
- childElements() {
3148
- return Array.from(this.currentEntityElement.childNodes);
3206
+ * @param {HTMLElement[]} elementsArray - Current elements.
3207
+ * @param {number} currentIndex - Current element index.
3208
+ * @returns {number} - can be handled element count.
3209
+ */
3210
+ canHandle(elementsArray, currentIndex) {
3211
+ let count = 0;
3212
+ for (let i = currentIndex; i < elementsArray.length; i++) {
3213
+ const element = elementsArray[i];
3214
+ if (element.nodeType === Node.TEXT_NODE ||
3215
+ (ContinueInlineToRTETextBlockStrategy.canHandleTags.includes(element.nodeName) &&
3216
+ !(element.textContent === '' && element.querySelector('IMG')))) {
3217
+ count++;
3218
+ }
3219
+ else {
3220
+ break;
3221
+ }
3222
+ }
3223
+ return count;
3149
3224
  }
3150
3225
  /**
3151
- * Format and append element for it block element.
3226
+ * Parse to a text block.
3152
3227
  *
3153
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3154
- * @returns {RTEContentBlock[]} - Block DTO.
3155
- */
3156
- handle(blockElement) {
3157
- const key = generateUUID();
3158
- Array.from(this.currentVirtualElement.children).forEach((childElement) => {
3159
- childElement.setAttribute('data-href', this.currentVirtualElement.href);
3160
- childElement.setAttribute('data-group-key', key);
3161
- (blockElement || ElementToDTOHandlerAbstract.getCurrentTextBlockElement()).append(childElement);
3228
+ * @param {HTMLElement[]} elementsArray - Current elements.
3229
+ * @returns {Nullable<RTEContentBlock>} - Text block.
3230
+ */
3231
+ handle(elementsArray) {
3232
+ const parent = elementsArray[0].parentElement;
3233
+ const nodes = this.generateChildNodes(elementsArray);
3234
+ if (nodes.length === 0)
3235
+ return null;
3236
+ return RTETextBlock.from({
3237
+ id: generateUUID(),
3238
+ type: 'paragraph',
3239
+ nodes: nodes,
3240
+ annotations: this.generateBlockAnnotations(parent),
3162
3241
  });
3163
- return [];
3164
3242
  }
3243
+ /* istanbul ignore next */
3165
3244
  /**
3166
- * Get the block element for child nodes
3245
+ * Append child blocks.
3246
+ */
3247
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
3248
+ appendChildBlocks() { }
3249
+ /**
3250
+ * Should continue process to child elements.
3167
3251
  *
3168
- * @returns {HTMLElement} - Block element for child nodes.
3252
+ * @returns {boolean} - boolean.
3169
3253
  */
3170
- getNextBlockElement() {
3171
- return this.currentVirtualElement;
3254
+ shouldProceedToElementChildren() {
3255
+ return false;
3172
3256
  }
3173
3257
  }
3258
+ ContinueInlineToRTETextBlockStrategy.canHandleTags = [
3259
+ 'SPAN',
3260
+ 'STRONG',
3261
+ 'CODE',
3262
+ 'I',
3263
+ 'EM',
3264
+ 'S',
3265
+ 'U',
3266
+ 'A',
3267
+ 'VEGA-RICH-TEXT-LINK-EDITOR',
3268
+ ];
3174
3269
 
3175
- /**
3176
- * Transform list element to DTO.
3177
- */
3178
- class ListItemToDTOHandler extends ElementToDTOHandlerAbstract {
3270
+ /** Transform ul element to list block DTO */
3271
+ class UlToRTEListBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3179
3272
  /**
3180
- * Can be transform.
3273
+ * Can be handle.
3181
3274
  *
3182
- * @param {HTMLElement} element - An pasted element.
3183
- * @returns {boolean} Result.
3275
+ * @param {HTMLElement[]} elementsArray - Current elements.
3276
+ * @param {number} currentIndex - Current element index.
3277
+ * @returns {number} - can be handled element count.
3184
3278
  */
3185
- static canHandle(element) {
3186
- return ['LI'].includes(element.nodeName);
3279
+ canHandle(elementsArray, currentIndex) {
3280
+ return elementsArray[currentIndex].tagName === 'UL' ? 1 : 0;
3187
3281
  }
3188
3282
  /**
3189
- * Special the child elements of current.
3283
+ * Parse to a block.
3190
3284
  *
3191
- * @returns {HTMLElement[]} - child elements.
3192
- */
3193
- childElements() {
3194
- return Array.from(this.currentEntityElement.childNodes);
3285
+ * @param {HTMLElement[]} elementsArray - Current elements.
3286
+ * @returns {Nullable<RTEContentBlock>} - Bullet list block.
3287
+ */
3288
+ handle(elementsArray) {
3289
+ if (elementsArray[0].childNodes.length === 0)
3290
+ return null;
3291
+ return RTEListBlock.from({
3292
+ id: generateUUID(),
3293
+ type: 'bullet-list',
3294
+ blocks: [],
3295
+ annotations: this.generateBlockAnnotations(elementsArray[0]),
3296
+ });
3195
3297
  }
3196
3298
  /**
3197
- * Append list item node to it block element.
3299
+ * Append child list item blocks to current list block.
3198
3300
  *
3199
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3200
- * @returns {RTEContentBlock[]} - Block DTO.
3301
+ * @param {RTEListBlock} currentBlock - Current list block.
3302
+ * @param {RTEListItemBlock[]} childBlocks - Current list item blocks.
3201
3303
  */
3202
- handle(blockElement) {
3203
- blockElement.append(this.currentVirtualElement);
3204
- return [];
3304
+ appendChildBlocks(currentBlock, childBlocks) {
3305
+ currentBlock.blocks = childBlocks;
3306
+ childBlocks.forEach((block) => (block.parent = currentBlock));
3205
3307
  }
3206
3308
  /**
3207
- * Get the block element for child nodes
3309
+ * Should continue process to child elements.
3208
3310
  *
3209
- * @returns {HTMLElement} - Block element for child nodes.
3311
+ * @returns {boolean} - boolean.
3210
3312
  */
3211
- getNextBlockElement() {
3212
- return this.currentVirtualElement;
3313
+ shouldProceedToElementChildren() {
3314
+ return true;
3213
3315
  }
3214
3316
  }
3215
3317
 
3216
- /**
3217
- * Transform list element to DTO.
3218
- */
3219
- class ListToDTOHandler extends ElementToDTOHandlerAbstract {
3318
+ /** Transform li element to list item block DTO */
3319
+ class LiToRTEListItemBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3220
3320
  /**
3221
- * Can be transform.
3321
+ * Can be handle.
3222
3322
  *
3223
- * @param {HTMLElement} element - An pasted element.
3224
- * @returns {boolean} Result.
3323
+ * @param {HTMLElement[]} elementsArray - Current elements.
3324
+ * @param {number} currentIndex - Current element index.
3325
+ * @returns {number} - can be handled element count.
3225
3326
  */
3226
- static canHandle(element) {
3227
- return ['UL', 'OL'].includes(element.nodeName);
3327
+ canHandle(elementsArray, currentIndex) {
3328
+ return elementsArray[currentIndex].tagName === 'LI' ? 1 : 0;
3228
3329
  }
3229
3330
  /**
3230
- * Special the child elements of current.
3331
+ * Parse to a list item block.
3231
3332
  *
3232
- * @returns {HTMLElement[]} - child elements.
3233
- */
3234
- childElements() {
3235
- return Array.from(this.currentEntityElement.childNodes);
3333
+ * @param {HTMLElement[]} elementsArray - Current elements.
3334
+ * @returns {Nullable<RTEContentBlock>} - List item block.
3335
+ */
3336
+ handle(elementsArray) {
3337
+ if (elementsArray[0].childNodes.length === 0)
3338
+ return null;
3339
+ return RTEListItemBlock.from({
3340
+ id: generateUUID(),
3341
+ type: 'list-item',
3342
+ nodes: this.generateChildNodes(Array.from(elementsArray[0].childNodes).filter((item) => !['UL', 'OL'].includes(item.nodeName))),
3343
+ annotations: this.generateBlockAnnotations(elementsArray[0]),
3344
+ });
3236
3345
  }
3237
3346
  /**
3238
- * Transform element to DTO.
3239
- * When blockElement is exist, it means that the current element is a child node,
3240
- * and we need to append and wait for its root block to be converted into a dto.
3241
- * Otherwise, the current node is the root node, and we can directly convert it.
3347
+ * Append child list blocks to current list item block.
3242
3348
  *
3243
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3244
- * @returns {RTEContentBlock[]} - Block DTO.
3349
+ * @param {RTEListBlock} currentBlock - Current list item block.
3350
+ * @param {RTEListItemBlock[]} childBlocks - Current list blocks.
3245
3351
  */
3246
- handle(blockElement) {
3247
- if (this.handleEmptyBlock(blockElement)) {
3248
- return [];
3249
- }
3250
- if (blockElement && ListItemToDTOHandler.canHandle(blockElement)) {
3251
- blockElement.append(this.currentVirtualElement);
3252
- return [];
3253
- }
3254
- else {
3255
- return [
3256
- ElementToDTOHandlerAbstract.currentTextBlockElementToDTO(),
3257
- RTEListBlock.fromHTML(this.currentVirtualElement),
3258
- ];
3259
- }
3352
+ appendChildBlocks(currentBlock, childBlocks) {
3353
+ currentBlock.children = childBlocks.filter((block) => ['bullet-list', 'number-list'].includes(block.type));
3260
3354
  }
3261
3355
  /**
3262
- * Get the block element for child nodes
3356
+ * Should continue process to child elements.
3263
3357
  *
3264
- * @returns {HTMLElement} - Block element for child nodes.
3358
+ * @returns {boolean} - boolean.
3265
3359
  */
3266
- getNextBlockElement() {
3267
- return this.currentVirtualElement;
3360
+ shouldProceedToElementChildren() {
3361
+ return true;
3268
3362
  }
3269
3363
  }
3270
3364
 
3271
- /**
3272
- * Transform paragraph.
3273
- */
3274
- class ParagraphToDTOHandler extends ElementToDTOHandlerAbstract {
3365
+ /** Transform inline block element to text block DTO */
3366
+ class InlineBlockToRTETextBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3275
3367
  /**
3276
- * Can be transform.
3368
+ * Can be handle.
3277
3369
  *
3278
- * @param {HTMLElement} element - An pasted element.
3279
- * @returns {boolean} Result.
3370
+ * @param {HTMLElement[]} elementsArray - Current elements.
3371
+ * @param {number} currentIndex - Current element index.
3372
+ * @returns {number} - can be handled element count.
3280
3373
  */
3281
- static canHandle(element) {
3282
- return ['DIV', 'P'].includes(element.nodeName);
3374
+ canHandle(elementsArray, currentIndex) {
3375
+ return ['heading-1', 'heading-2', 'heading-3', 'title', 'subtitle'].includes(this.getElementType(elementsArray[currentIndex]))
3376
+ ? 1
3377
+ : 0;
3283
3378
  }
3284
3379
  /**
3285
- * Special the child elements of current.
3380
+ * Parse to a text block.
3286
3381
  *
3287
- * @returns {HTMLElement[]} - child elements.
3288
- */
3289
- childElements() {
3290
- return Array.from(this.currentEntityElement.childNodes);
3291
- }
3292
- /**
3293
- * Transform element to DTO.
3294
- * When blockElement is exist, it means that the current element is a child node,
3295
- * and we need to wait for its root block to be converted into a dto.
3296
- * Otherwise, the current node is the root node, and we can directly convert it.
3297
- *
3298
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3299
- * @returns {RTEContentBlock[]} - Block DTO.
3300
- */
3301
- handle(blockElement) {
3302
- if (this.handleEmptyBlock(blockElement)) {
3303
- return [];
3304
- }
3305
- if (blockElement && !ParagraphToDTOHandler.canHandle(blockElement)) {
3306
- blockElement.append(...Array.from(this.currentVirtualElement.childNodes));
3307
- return [];
3308
- }
3309
- else {
3310
- return [
3311
- ElementToDTOHandlerAbstract.currentTextBlockElementToDTO(),
3312
- RTETextBlock.fromHTML(this.currentVirtualElement, 'paragraph'),
3313
- ];
3314
- }
3382
+ * @param {HTMLElement[]} elementsArray - Current elements.
3383
+ * @returns {Nullable<RTEContentBlock>} - Text block.
3384
+ */
3385
+ handle(elementsArray) {
3386
+ const nodes = this.generateChildNodes(elementsArray);
3387
+ if (nodes.length === 0)
3388
+ return null;
3389
+ return RTETextBlock.from({
3390
+ id: generateUUID(),
3391
+ type: this.getElementType(elementsArray[0]),
3392
+ nodes: nodes,
3393
+ annotations: Object.assign(Object.assign({}, this.generateBlockAnnotations(elementsArray[0])), { textStyle: this.getElementType(elementsArray[0]) }),
3394
+ });
3315
3395
  }
3396
+ /* istanbul ignore next */
3316
3397
  /**
3317
- * Get the block element for child nodes
3318
- *
3319
- * @returns {HTMLElement} - Block element for child nodes.
3398
+ * Append child blocks.
3320
3399
  */
3321
- getNextBlockElement() {
3322
- return this.currentVirtualElement;
3323
- }
3324
- }
3325
-
3326
- /**
3327
- * Transform text block element to DTO.
3328
- */
3329
- class TextBlockToDTOHandler extends ElementToDTOHandlerAbstract {
3400
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
3401
+ appendChildBlocks() { }
3330
3402
  /**
3331
- * Can be transform.
3403
+ * Should continue process to child elements.
3332
3404
  *
3333
- * @param {HTMLElement} element - An pasted element.
3334
- * @returns {boolean} Result.
3405
+ * @returns {boolean} - boolean.
3335
3406
  */
3336
- static canHandle(element) {
3337
- return ['heading-1', 'heading-2', 'heading-3', 'title', 'subtitle'].includes(this.getElementType(element));
3407
+ shouldProceedToElementChildren() {
3408
+ return false;
3338
3409
  }
3339
3410
  /**
3340
- * Get type of element.
3411
+ * Get node type of element.
3341
3412
  *
3342
- * @param {HTMLElement} element - An pasted element.
3343
- * @returns {string} type.
3413
+ * @param {HTMLElement} element - element.
3414
+ * @returns {string} - node type.
3344
3415
  */
3345
- static getElementType(element) {
3416
+ getElementType(element) {
3417
+ var _a;
3346
3418
  if (element.nodeType !== Node.TEXT_NODE && element.hasAttribute('data-type')) {
3347
3419
  return element.getAttribute('data-type');
3348
3420
  }
3421
+ switch ((_a = element.style) === null || _a === void 0 ? void 0 : _a.fontSize) {
3422
+ case '36px':
3423
+ return 'title';
3424
+ case '28px':
3425
+ return 'subtitle';
3426
+ case '22px':
3427
+ return 'heading-1';
3428
+ case '20px':
3429
+ return 'heading-2';
3430
+ case '18px':
3431
+ return 'heading-3';
3432
+ }
3349
3433
  switch (element.nodeName) {
3350
3434
  case 'H1':
3351
3435
  return 'heading-1';
@@ -3357,139 +3441,269 @@ class TextBlockToDTOHandler extends ElementToDTOHandlerAbstract {
3357
3441
  return '';
3358
3442
  }
3359
3443
  }
3444
+ }
3445
+
3446
+ /** Transform img element to image block DTO */
3447
+ class ImgToRTEImageBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3360
3448
  /**
3361
- * Special the child elements of current.
3449
+ * Can be handle.
3362
3450
  *
3363
- * @returns {HTMLElement[]} - child elements.
3451
+ * @param {HTMLElement[]} elementsArray - Current elements.
3452
+ * @param {number} currentIndex - Current element index.
3453
+ * @returns {number} - can be handled element count.
3364
3454
  */
3365
- childElements() {
3366
- return Array.from(this.currentEntityElement.childNodes);
3455
+ canHandle(elementsArray, currentIndex) {
3456
+ return elementsArray[currentIndex].tagName === 'IMG' ? 1 : 0;
3367
3457
  }
3368
3458
  /**
3369
- * Transform element to DTO.
3370
- * When blockElement is exist, it means that the current element is a child node,
3371
- * and we need to wait for its root block to be converted into a dto.
3372
- * Otherwise, the current node is the root node, and we can directly convert it.
3459
+ * Parse to a image block.
3373
3460
  *
3374
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3375
- * @returns {RTEContentBlock[]} - Block DTO.
3376
- */
3377
- handle(blockElement) {
3378
- if (this.handleEmptyBlock(blockElement)) {
3379
- return [];
3380
- }
3381
- if (blockElement) {
3382
- blockElement.append(...Array.from(this.currentVirtualElement.childNodes));
3383
- return [];
3384
- }
3385
- else {
3386
- return [
3387
- ElementToDTOHandlerAbstract.currentTextBlockElementToDTO(),
3388
- RTETextBlock.fromHTML(this.currentVirtualElement, TextBlockToDTOHandler.getElementType(this.currentVirtualElement)),
3389
- ];
3390
- }
3461
+ * @param {HTMLElement[]} elementsArray - Current elements.
3462
+ * @returns {Nullable<RTEContentBlock>} - Image block.
3463
+ */
3464
+ handle(elementsArray) {
3465
+ const element = elementsArray[0];
3466
+ return RTEImageBlock.from({
3467
+ id: generateUUID(),
3468
+ type: 'image',
3469
+ nodes: [
3470
+ {
3471
+ id: generateUUID(),
3472
+ type: 'image',
3473
+ url: element.src,
3474
+ annotations: {
3475
+ size: 'md',
3476
+ alt: element.alt,
3477
+ },
3478
+ },
3479
+ ],
3480
+ annotations: this.generateBlockAnnotations(element),
3481
+ });
3391
3482
  }
3483
+ /* istanbul ignore next */
3392
3484
  /**
3393
- * Get the block element for child nodes
3485
+ * Append child blocks.
3486
+ */
3487
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
3488
+ appendChildBlocks() { }
3489
+ /**
3490
+ * Should continue process to child elements.
3394
3491
  *
3395
- * @returns {HTMLElement} - Block element for child nodes.
3492
+ * @returns {boolean} - boolean.
3396
3493
  */
3397
- getNextBlockElement() {
3398
- return this.currentVirtualElement;
3494
+ shouldProceedToElementChildren() {
3495
+ return false;
3399
3496
  }
3400
3497
  }
3401
3498
 
3402
- /**
3403
- * Transform text element to DTO.
3404
- */
3405
- class TextToDTOHandler extends ElementToDTOHandlerAbstract {
3499
+ /** Transform vega-rich-text-image-editor element to image block DTO */
3500
+ class VegaImageToRTEImageBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3406
3501
  /**
3407
- * Can be transform.
3502
+ * Can be handle.
3408
3503
  *
3409
- * @param {HTMLElement} element - An pasted element.
3410
- * @returns {boolean} Result.
3504
+ * @param {HTMLElement[]} elementsArray - Current elements.
3505
+ * @param {number} currentIndex - Current element index.
3506
+ * @returns {number} - can be handled element count.
3411
3507
  */
3412
- static canHandle(element) {
3413
- return element.nodeType === Node.TEXT_NODE;
3508
+ canHandle(elementsArray, currentIndex) {
3509
+ return elementsArray[currentIndex].tagName === 'VEGA-RICH-TEXT-IMAGE-EDITOR' ? 1 : 0;
3510
+ }
3511
+ /**
3512
+ * Parse to a image block.
3513
+ *
3514
+ * @param {HTMLElement[]} elementsArray - Current elements.
3515
+ * @returns {Nullable<RTEContentBlock>} - Image block.
3516
+ */
3517
+ handle(elementsArray) {
3518
+ const element = elementsArray[0];
3519
+ const image = element.querySelector('img');
3520
+ return RTEImageBlock.from({
3521
+ id: generateUUID(),
3522
+ type: 'image',
3523
+ nodes: [
3524
+ {
3525
+ id: generateUUID(),
3526
+ type: 'image',
3527
+ url: image.src,
3528
+ annotations: {
3529
+ size: element.size || 'md',
3530
+ alt: element.alt,
3531
+ },
3532
+ },
3533
+ ],
3534
+ annotations: this.generateBlockAnnotations(element),
3535
+ });
3414
3536
  }
3415
3537
  /* istanbul ignore next */
3416
3538
  /**
3417
- * Special the child elements of current.
3539
+ * Append child blocks.
3540
+ */
3541
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
3542
+ appendChildBlocks() { }
3543
+ /**
3544
+ * Should continue process to child elements.
3418
3545
  *
3419
- * @returns {HTMLElement[]} - child elements.
3546
+ * @returns {boolean} - boolean.
3420
3547
  */
3421
- childElements() {
3422
- return [];
3548
+ shouldProceedToElementChildren() {
3549
+ return false;
3423
3550
  }
3551
+ }
3552
+
3553
+ /** Transform ol element to list block DTO */
3554
+ class OlToRTEListBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3424
3555
  /**
3425
- * Append text node to it block element.
3556
+ * Can be handle.
3426
3557
  *
3427
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3428
- * @returns {RTEContentBlock[]} - Block DTO.
3558
+ * @param {HTMLElement[]} elementsArray - Current elements.
3559
+ * @param {number} currentIndex - Current element index.
3560
+ * @returns {number} - can be handled element count.
3429
3561
  */
3430
- handle(blockElement) {
3431
- (blockElement || ElementToDTOHandlerAbstract.getCurrentTextBlockElement()).append(this.currentVirtualElement);
3432
- return [];
3562
+ canHandle(elementsArray, currentIndex) {
3563
+ return elementsArray[currentIndex].tagName === 'OL' ? 1 : 0;
3564
+ }
3565
+ /**
3566
+ * Parse to a number list block.
3567
+ *
3568
+ * @param {HTMLElement[]} elementsArray - Current elements.
3569
+ * @returns {Nullable<RTEContentBlock>} - Number list block.
3570
+ */
3571
+ handle(elementsArray) {
3572
+ if (elementsArray[0].childNodes.length === 0)
3573
+ return null;
3574
+ return RTEListBlock.from({
3575
+ id: generateUUID(),
3576
+ type: 'number-list',
3577
+ blocks: [],
3578
+ annotations: this.generateBlockAnnotations(elementsArray[0]),
3579
+ });
3580
+ }
3581
+ /**
3582
+ * Append child list item blocks to current list block.
3583
+ *
3584
+ * @param {RTEListBlock} currentBlock - Current list block.
3585
+ * @param {RTEListItemBlock[]} childBlocks - Current list item blocks.
3586
+ */
3587
+ appendChildBlocks(currentBlock, childBlocks) {
3588
+ currentBlock.blocks = childBlocks;
3589
+ childBlocks.forEach((block) => (block.parent = currentBlock));
3433
3590
  }
3434
- /* istanbul ignore next */
3435
3591
  /**
3436
- * Get the block element for child nodes
3592
+ * Should continue process to child elements.
3437
3593
  *
3438
- * @param {Nullable<HTMLElement>} blockElement - Current block container.
3439
- * @returns {Nullable<HTMLElement>} - blockElement.
3594
+ * @returns {boolean} - boolean.
3440
3595
  */
3441
- getNextBlockElement(blockElement) {
3442
- return blockElement;
3596
+ shouldProceedToElementChildren() {
3597
+ return true;
3443
3598
  }
3444
3599
  }
3445
3600
 
3446
- /**
3447
- * Element to DTO processor
3448
- */
3449
- class ElementToDTOProcessor {
3450
- constructor() {
3451
- this.elementHandlers = [
3452
- TextToDTOHandler,
3453
- ImageToDTOHandler,
3454
- ListToDTOHandler,
3455
- ListItemToDTOHandler,
3456
- TextBlockToDTOHandler,
3457
- ParagraphToDTOHandler,
3458
- LinkToDTOHandler,
3459
- InlineBlockToDTOHandler,
3460
- ];
3601
+ /** Transform img in span or other inline element to image block DTO */
3602
+ class SpanImageToRTEImageBlockStrategy extends BlockToRTEBlockStrategyAbstract {
3603
+ /**
3604
+ * Can be handle.
3605
+ *
3606
+ * @param {HTMLElement[]} elementsArray - Current elements.
3607
+ * @param {number} currentIndex - Current element index.
3608
+ * @returns {number} - can be handled element count.
3609
+ */
3610
+ canHandle(elementsArray, currentIndex) {
3611
+ const element = elementsArray[currentIndex];
3612
+ return element.nodeType === Node.ELEMENT_NODE &&
3613
+ element.textContent === '' &&
3614
+ element.querySelector('img')
3615
+ ? 1
3616
+ : 0;
3617
+ }
3618
+ /**
3619
+ * Parse to a image block.
3620
+ *
3621
+ * @param {HTMLElement[]} elementsArray - Current elements.
3622
+ * @returns {Nullable<RTEContentBlock>} - Image block.
3623
+ */
3624
+ handle(elementsArray) {
3625
+ const element = elementsArray[0].querySelector('img');
3626
+ return RTEImageBlock.from({
3627
+ id: generateUUID(),
3628
+ type: 'image',
3629
+ nodes: [
3630
+ {
3631
+ id: generateUUID(),
3632
+ type: 'image',
3633
+ url: element.src,
3634
+ annotations: {
3635
+ size: 'md',
3636
+ alt: element.alt,
3637
+ },
3638
+ },
3639
+ ],
3640
+ annotations: this.generateBlockAnnotations(element),
3641
+ });
3461
3642
  }
3643
+ /* istanbul ignore next */
3462
3644
  /**
3463
- * Transform element to block DTO.
3645
+ * Append child blocks.
3646
+ */
3647
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
3648
+ appendChildBlocks() { }
3649
+ /**
3650
+ * Should continue process to child elements.
3464
3651
  *
3465
- * @param {HTMLElement} element - An pasted element.
3466
- * @returns {RTEContentBlock[]} Block DTO.
3652
+ * @returns {boolean} - boolean.
3467
3653
  */
3468
- process(element) {
3469
- const blocks = this.transformDomToDto(Array.from(element.childNodes), null);
3470
- blocks.push(ElementToDTOHandlerAbstract.currentTextBlockElementToDTO());
3471
- return blocks.filter(Boolean);
3654
+ shouldProceedToElementChildren() {
3655
+ return false;
3656
+ }
3657
+ }
3658
+
3659
+ /** Element to DTO processor */
3660
+ class ElementToDtoStrategyProcessor {
3661
+ constructor() {
3662
+ this.elementStrategies = [
3663
+ new UlToRTEListBlockStrategy(),
3664
+ new OlToRTEListBlockStrategy(),
3665
+ new LiToRTEListItemBlockStrategy(),
3666
+ new InlineBlockToRTETextBlockStrategy(),
3667
+ new ImgToRTEImageBlockStrategy(),
3668
+ new VegaImageToRTEImageBlockStrategy(),
3669
+ new SpanImageToRTEImageBlockStrategy(),
3670
+ new ContinueInlineToRTETextBlockStrategy(),
3671
+ ];
3472
3672
  }
3473
3673
  /**
3474
- * Transform elements to block DTO.
3674
+ * Transform process.
3475
3675
  *
3476
- * @param {HTMLElement[]} elements - An pasted elements.
3477
- * @param {HTMLElement} blockElement - Current block element.
3478
- * @returns {RTEContentBlock[]} Block DTO.
3479
- */
3480
- transformDomToDto(elements, blockElement) {
3481
- const rootBlocks = [];
3482
- elements.forEach((element) => {
3483
- if (this.isInvalidElement(element))
3484
- return;
3485
- const handler = this.elementHandlers.find((elementHandler) => elementHandler.canHandle(element));
3486
- const handle = new handler(element);
3487
- if (element.nodeType !== Node.TEXT_NODE) {
3488
- rootBlocks.push(...this.transformDomToDto(handle.childElements(), handle.getNextBlockElement(blockElement)));
3676
+ * @param {HTMLElement[]} elements - Current elements.
3677
+ * @returns {ElementToDTOStrategyOutput[]} - outputs.
3678
+ */
3679
+ process(elements) {
3680
+ const outputs = [];
3681
+ for (let i = 0; i < elements.length; i++) {
3682
+ if (this.isInvalidElement(elements[i]))
3683
+ continue;
3684
+ let canHandledCount = 0;
3685
+ for (const strategy of this.elementStrategies) {
3686
+ canHandledCount = strategy.canHandle(elements, i);
3687
+ if (canHandledCount > 0) {
3688
+ const handledElements = elements.slice(i, i + canHandledCount);
3689
+ const output = new ElementToDTOStrategyOutput(strategy, handledElements);
3690
+ if (canHandledCount === 1 && strategy.shouldProceedToElementChildren()) {
3691
+ output.setChildrenOutput(this.process(Array.from(handledElements[0].childNodes)));
3692
+ }
3693
+ outputs.push(output);
3694
+ i += canHandledCount - 1;
3695
+ break;
3696
+ }
3489
3697
  }
3490
- rootBlocks.push(...handle.handle(blockElement));
3491
- });
3492
- return rootBlocks;
3698
+ if (canHandledCount === 0 && i < elements.length) {
3699
+ const elementChildren = Array.from(elements[i].childNodes);
3700
+ const childrenOutputs = this.process(Array.from(elementChildren));
3701
+ if (childrenOutputs.length > 0) {
3702
+ outputs.push(...childrenOutputs);
3703
+ }
3704
+ }
3705
+ }
3706
+ return outputs;
3493
3707
  }
3494
3708
  /**
3495
3709
  * Checks if the given element is valid to parse.
@@ -3500,11 +3714,6 @@ class ElementToDTOProcessor {
3500
3714
  isInvalidElement(element) {
3501
3715
  if (element.nodeType === Node.COMMENT_NODE)
3502
3716
  return true;
3503
- if (element.nodeType === Node.TEXT_NODE && element.nodeValue.includes('\t')) {
3504
- const value = element.nodeValue.replace(/\n|\t/gm, '');
3505
- if (value.length === 0)
3506
- return true;
3507
- }
3508
3717
  return ['META', 'BUTTON', 'STYLE'].includes(element.nodeName);
3509
3718
  }
3510
3719
  }
@@ -3515,7 +3724,7 @@ class ElementToDTOProcessor {
3515
3724
  class InsertPasteHandler extends BaseHandler {
3516
3725
  constructor() {
3517
3726
  super(...arguments);
3518
- this.elementToDTOProcessor = new ElementToDTOProcessor();
3727
+ this.elementToDTOProcessor = new ElementToDtoStrategyProcessor();
3519
3728
  }
3520
3729
  /**
3521
3730
  * Update the state value when user paste html elements.
@@ -3581,7 +3790,11 @@ class InsertPasteHandler extends BaseHandler {
3581
3790
  const pastedHTML = event.dataTransfer.getData('text/html');
3582
3791
  const tempContainer = document.createElement('div');
3583
3792
  tempContainer.innerHTML = pastedHTML;
3584
- return this.elementToDTOProcessor.process(tempContainer);
3793
+ return this.elementToDTOProcessor
3794
+ .process(Array.from(tempContainer.childNodes))
3795
+ .filter(Boolean)
3796
+ .map((output) => output.toDto())
3797
+ .filter(Boolean);
3585
3798
  }
3586
3799
  /**
3587
3800
  * Moves the caret to the next block element in a rich text editor.