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