@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.
- package/dist/cjs/{app-globals-4e819773.js → app-globals-48582633.js} +2 -2
- package/dist/cjs/{content-state-3a2724f6.js → content-state-6a5b9736.js} +64 -294
- package/dist/cjs/index.cjs.js +2 -2
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/{text-color-toolbar-button-slimmer-b1c9f40e.js → text-color-toolbar-button-slimmer-21a166e4.js} +1 -1
- package/dist/cjs/{text-node-0d12da5a.js → text-node-494856f3.js} +0 -122
- package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
- package/dist/cjs/vega-pagination.cjs.entry.js +5 -2
- package/dist/cjs/vega-rich-text-content.cjs.entry.js +2 -2
- package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +629 -416
- package/dist/cjs/vega-table_8.cjs.entry.js +1 -1
- package/dist/cjs/vega.cjs.js +3 -3
- package/dist/collection/components/vega-pagination/vega-pagination.js +5 -2
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/bold-annotation.js +0 -10
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/code-annotation.js +0 -9
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/horizontal-alignment-annotation.js +0 -44
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/image-annotation.js +0 -10
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/indent-annotation.js +0 -42
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/italic-annotation.js +0 -9
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/link-annotation.js +0 -14
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/strikethrough-annotation.js +0 -11
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-color-annotation.js +0 -26
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-style-annotation.js +0 -44
- package/dist/collection/components/vega-rich-text-editor/dto/annotations/underline-annotation.js +0 -11
- package/dist/collection/components/vega-rich-text-editor/dto/blocks/block.abstract.js +0 -18
- package/dist/collection/components/vega-rich-text-editor/dto/blocks/image-block.js +0 -13
- package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-block.js +0 -19
- package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-item-block.js +0 -27
- package/dist/collection/components/vega-rich-text-editor/dto/blocks/text-block.js +2 -14
- package/dist/collection/components/vega-rich-text-editor/dto/nodes/image-node.js +0 -10
- package/dist/collection/components/vega-rich-text-editor/dto/nodes/text-node.js +0 -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
- 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
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy-processor.js +70 -0
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy.abstract.js +37 -0
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/img-to-rte-image-block-strategy.js +55 -0
- 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
- 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
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ol-to-rte-list-block-strategy.js +50 -0
- 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
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/ul-to-rte-list-block-strategy.js +50 -0
- 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
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/input-event-handler/insert-paste-handler.js +7 -3
- package/dist/collection/components/vega-table/vega-table-head-cell/vega-table-head-cell.css +3 -0
- package/dist/esm/{app-globals-9971ccfd.js → app-globals-48531a04.js} +2 -2
- package/dist/esm/{content-state-acf55eb0.js → content-state-4b036bf1.js} +65 -295
- package/dist/esm/index.js +2 -2
- package/dist/esm/loader.js +3 -3
- package/dist/esm/{text-color-toolbar-button-slimmer-d0255b98.js → text-color-toolbar-button-slimmer-b2270b64.js} +1 -1
- package/dist/esm/{text-node-6f7d736c.js → text-node-a652ca87.js} +0 -122
- package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
- package/dist/esm/vega-pagination.entry.js +5 -2
- package/dist/esm/vega-rich-text-content.entry.js +2 -2
- package/dist/esm/vega-rich-text-editor_4.entry.js +630 -417
- package/dist/esm/vega-table_8.entry.js +1 -1
- package/dist/esm/vega.js +3 -3
- package/dist/types/components/vega-pagination/vega-pagination.d.ts +1 -0
- package/dist/types/components/vega-rich-text-editor/dto/annotations/bold-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/code-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/horizontal-alignment-annotation.d.ts +0 -14
- package/dist/types/components/vega-rich-text-editor/dto/annotations/image-annotation.d.ts +0 -8
- package/dist/types/components/vega-rich-text-editor/dto/annotations/indent-annotation.d.ts +0 -14
- package/dist/types/components/vega-rich-text-editor/dto/annotations/italic-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/link-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/strikethrough-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/text-color-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/annotations/text-style-annotation.d.ts +0 -14
- package/dist/types/components/vega-rich-text-editor/dto/annotations/underline-annotation.d.ts +0 -7
- package/dist/types/components/vega-rich-text-editor/dto/blocks/block.abstract.d.ts +0 -8
- package/dist/types/components/vega-rich-text-editor/dto/blocks/image-block.d.ts +0 -1
- package/dist/types/components/vega-rich-text-editor/dto/blocks/list-block.d.ts +0 -1
- package/dist/types/components/vega-rich-text-editor/dto/blocks/list-item-block.d.ts +0 -1
- package/dist/types/components/vega-rich-text-editor/dto/blocks/text-block.d.ts +0 -1
- package/dist/types/components/vega-rich-text-editor/dto/nodes/image-node.d.ts +0 -1
- package/dist/types/components/vega-rich-text-editor/dto/nodes/text-node.d.ts +0 -2
- 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
- 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
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy-processor.d.ts +19 -0
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/element-to-dto-strategy.abstract.d.ts +32 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/dist/vega/index.esm.js +1 -1
- package/dist/vega/{p-d302f052.entry.js → p-0190095c.entry.js} +1 -1
- package/dist/vega/p-10393104.js +1 -0
- package/dist/vega/p-584dcd9b.js +1 -0
- package/dist/vega/p-5f377954.js +1 -1
- package/dist/vega/{p-c1d97d12.entry.js → p-734ea281.entry.js} +1 -1
- package/dist/vega/{p-49f4a666.js → p-8836c1b9.js} +1 -1
- package/dist/vega/p-8f004647.entry.js +1 -0
- package/dist/vega/p-9e732a26.entry.js +1 -0
- package/dist/vega/{p-2fc3af2f.js → p-9f39dd10.js} +1 -1
- package/dist/vega/vega.esm.js +1 -1
- package/package.json +1 -1
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-handler.abstract.js +0 -135
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-processor.js +0 -74
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/image-to-dto-handler.js +0 -47
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/inline-block-to-dto-handler.js +0 -39
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/link-to-dto-handler.js +0 -50
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-item-to-dto-handler.js +0 -41
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-to-dto-handler.js +0 -57
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/paragraph-to-dto-handler.js +0 -56
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-block-to-dto-handler.js +0 -77
- package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-to-dto-handler.js +0 -44
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-handler.abstract.d.ts +0 -67
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/element-to-dto-processor.d.ts +0 -29
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/image-to-dto-handler.d.ts +0 -37
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/inline-block-to-dto-handler.d.ts +0 -35
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/link-to-dto-handler.d.ts +0 -37
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-item-to-dto-handler.d.ts +0 -36
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/list-to-dto-handler.d.ts +0 -39
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/paragraph-to-dto-handler.d.ts +0 -39
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-block-to-dto-handler.d.ts +0 -46
- package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-handler/text-to-dto-handler.d.ts +0 -37
- package/dist/vega/p-315667f1.js +0 -1
- package/dist/vega/p-728b029a.entry.js +0 -1
- package/dist/vega/p-b6af0fc1.entry.js +0 -1
- 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-
|
|
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-
|
|
14
|
+
const contentState = require('./content-state-6a5b9736.js');
|
|
15
15
|
const node_abstract = require('./node.abstract-f8075f84.js');
|
|
16
|
-
const textNode = require('./text-node-
|
|
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
|
|
2913
|
+
* Abstract class to define strategies for processing HTML elements
|
|
2914
2914
|
*/
|
|
2915
|
-
class
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
this.
|
|
2924
|
-
this.
|
|
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
|
-
*
|
|
2927
|
+
* Set children output.
|
|
2930
2928
|
*
|
|
2931
|
-
* @param {
|
|
2932
|
-
* @returns {boolean} Can be handle.
|
|
2929
|
+
* @param {ElementToDTOStrategyOutput[]} childrenOutput - children outputs.
|
|
2933
2930
|
*/
|
|
2934
|
-
|
|
2935
|
-
|
|
2931
|
+
setChildrenOutput(childrenOutput) {
|
|
2932
|
+
this.childrenOutput = childrenOutput;
|
|
2936
2933
|
}
|
|
2937
2934
|
/**
|
|
2938
|
-
* Transform current
|
|
2935
|
+
* Transform current output and children output to DTO
|
|
2939
2936
|
*
|
|
2940
|
-
* @returns {
|
|
2941
|
-
*/
|
|
2942
|
-
|
|
2943
|
-
const
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
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
|
-
*
|
|
2993
|
+
* Generate annotations map for block element.
|
|
2965
2994
|
*
|
|
2966
|
-
* @param {HTMLElement}
|
|
2967
|
-
* @returns {
|
|
2995
|
+
* @param {HTMLElement} element - current element.
|
|
2996
|
+
* @returns {VegaRTEBlockAnnotations} - Text block annotations.
|
|
2968
2997
|
*/
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
2982
|
-
if (element.
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
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
|
-
|
|
3008
|
-
element.classList.add(...Array.from(parentClass));
|
|
3020
|
+
return false;
|
|
3009
3021
|
}
|
|
3010
3022
|
/**
|
|
3011
|
-
*
|
|
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 -
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
if (element
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
this.
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
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
|
-
*
|
|
3046
|
+
* Is code element.
|
|
3034
3047
|
*
|
|
3035
|
-
* @
|
|
3048
|
+
* @param {HTMLElement} element - current element.
|
|
3049
|
+
* @returns {boolean} - boolean.
|
|
3036
3050
|
*/
|
|
3037
|
-
|
|
3038
|
-
|
|
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
|
-
*
|
|
3055
|
+
* Is bold element.
|
|
3051
3056
|
*
|
|
3052
|
-
* @param {HTMLElement} element -
|
|
3053
|
-
* @returns {boolean}
|
|
3057
|
+
* @param {HTMLElement} element - current element.
|
|
3058
|
+
* @returns {boolean} - boolean.
|
|
3054
3059
|
*/
|
|
3055
|
-
|
|
3056
|
-
return (element.
|
|
3057
|
-
|
|
3060
|
+
isBold(element) {
|
|
3061
|
+
return (element.nodeName === 'STRONG' ||
|
|
3062
|
+
element.style.fontWeight === 'bold' ||
|
|
3063
|
+
element.style.fontWeight === '700');
|
|
3058
3064
|
}
|
|
3059
3065
|
/**
|
|
3060
|
-
*
|
|
3066
|
+
* Is italic element.
|
|
3061
3067
|
*
|
|
3062
|
-
* @
|
|
3068
|
+
* @param {HTMLElement} element - current element.
|
|
3069
|
+
* @returns {boolean} - boolean.
|
|
3063
3070
|
*/
|
|
3064
|
-
|
|
3065
|
-
return
|
|
3071
|
+
isItalic(element) {
|
|
3072
|
+
return element.nodeName === 'I' || element.style.fontStyle === 'italic' || element.nodeName === 'EM';
|
|
3066
3073
|
}
|
|
3067
3074
|
/**
|
|
3068
|
-
*
|
|
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
|
-
* @
|
|
3077
|
+
* @param {HTMLElement} element - current element.
|
|
3078
|
+
* @returns {boolean} - boolean.
|
|
3074
3079
|
*/
|
|
3075
|
-
|
|
3076
|
-
return
|
|
3077
|
-
|
|
3078
|
-
|
|
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
|
-
*
|
|
3086
|
+
* Is strikethrough element.
|
|
3083
3087
|
*
|
|
3084
|
-
* @
|
|
3088
|
+
* @param {HTMLElement} element - current element.
|
|
3089
|
+
* @returns {boolean} - boolean.
|
|
3085
3090
|
*/
|
|
3086
|
-
|
|
3087
|
-
return
|
|
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
|
-
*
|
|
3097
|
+
* Get current color of element.
|
|
3097
3098
|
*
|
|
3098
|
-
* @
|
|
3099
|
+
* @param {HTMLElement} element - current element.
|
|
3100
|
+
* @returns {Nullable<string>} - color.
|
|
3099
3101
|
*/
|
|
3100
|
-
|
|
3101
|
-
|
|
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
|
-
*
|
|
3122
|
+
* Get current link of element.
|
|
3105
3123
|
*
|
|
3106
|
-
* @
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
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
|
-
*
|
|
3137
|
+
* Get text align of current element.
|
|
3113
3138
|
*
|
|
3114
|
-
* @
|
|
3139
|
+
* @param {HTMLElement} element - current element.
|
|
3140
|
+
* @returns {Nullable<VegaRTEBlockAlignment>} - Text align.
|
|
3115
3141
|
*/
|
|
3116
|
-
|
|
3117
|
-
|
|
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
|
|
3171
|
+
* Get indent of current element.
|
|
3121
3172
|
*
|
|
3122
|
-
* @param {
|
|
3123
|
-
* @returns {Nullable<
|
|
3124
|
-
*/
|
|
3125
|
-
|
|
3126
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
3208
|
+
* Can be handle.
|
|
3148
3209
|
*
|
|
3149
|
-
* @
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
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
|
-
*
|
|
3230
|
+
* Parse to a text block.
|
|
3156
3231
|
*
|
|
3157
|
-
* @param {
|
|
3158
|
-
* @returns {RTEContentBlock
|
|
3159
|
-
*/
|
|
3160
|
-
handle(
|
|
3161
|
-
const
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
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
|
-
*
|
|
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 {
|
|
3256
|
+
* @returns {boolean} - boolean.
|
|
3173
3257
|
*/
|
|
3174
|
-
|
|
3175
|
-
return
|
|
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
|
-
|
|
3181
|
-
*/
|
|
3182
|
-
class ListItemToDTOHandler extends ElementToDTOHandlerAbstract {
|
|
3274
|
+
/** Transform ul element to list block DTO */
|
|
3275
|
+
class UlToRTEListBlockStrategy extends BlockToRTEBlockStrategyAbstract {
|
|
3183
3276
|
/**
|
|
3184
|
-
* Can be
|
|
3277
|
+
* Can be handle.
|
|
3185
3278
|
*
|
|
3186
|
-
* @param {HTMLElement}
|
|
3187
|
-
* @
|
|
3279
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3280
|
+
* @param {number} currentIndex - Current element index.
|
|
3281
|
+
* @returns {number} - can be handled element count.
|
|
3188
3282
|
*/
|
|
3189
|
-
|
|
3190
|
-
return ['
|
|
3283
|
+
canHandle(elementsArray, currentIndex) {
|
|
3284
|
+
return elementsArray[currentIndex].tagName === 'UL' ? 1 : 0;
|
|
3191
3285
|
}
|
|
3192
3286
|
/**
|
|
3193
|
-
*
|
|
3287
|
+
* Parse to a block.
|
|
3194
3288
|
*
|
|
3195
|
-
* @
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
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
|
|
3303
|
+
* Append child list item blocks to current list block.
|
|
3202
3304
|
*
|
|
3203
|
-
* @param {
|
|
3204
|
-
* @
|
|
3305
|
+
* @param {RTEListBlock} currentBlock - Current list block.
|
|
3306
|
+
* @param {RTEListItemBlock[]} childBlocks - Current list item blocks.
|
|
3205
3307
|
*/
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3308
|
+
appendChildBlocks(currentBlock, childBlocks) {
|
|
3309
|
+
currentBlock.blocks = childBlocks;
|
|
3310
|
+
childBlocks.forEach((block) => (block.parent = currentBlock));
|
|
3209
3311
|
}
|
|
3210
3312
|
/**
|
|
3211
|
-
*
|
|
3313
|
+
* Should continue process to child elements.
|
|
3212
3314
|
*
|
|
3213
|
-
* @returns {
|
|
3315
|
+
* @returns {boolean} - boolean.
|
|
3214
3316
|
*/
|
|
3215
|
-
|
|
3216
|
-
return
|
|
3317
|
+
shouldProceedToElementChildren() {
|
|
3318
|
+
return true;
|
|
3217
3319
|
}
|
|
3218
3320
|
}
|
|
3219
3321
|
|
|
3220
|
-
/**
|
|
3221
|
-
|
|
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
|
|
3325
|
+
* Can be handle.
|
|
3226
3326
|
*
|
|
3227
|
-
* @param {HTMLElement}
|
|
3228
|
-
* @
|
|
3327
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3328
|
+
* @param {number} currentIndex - Current element index.
|
|
3329
|
+
* @returns {number} - can be handled element count.
|
|
3229
3330
|
*/
|
|
3230
|
-
|
|
3231
|
-
return ['
|
|
3331
|
+
canHandle(elementsArray, currentIndex) {
|
|
3332
|
+
return elementsArray[currentIndex].tagName === 'LI' ? 1 : 0;
|
|
3232
3333
|
}
|
|
3233
3334
|
/**
|
|
3234
|
-
*
|
|
3335
|
+
* Parse to a list item block.
|
|
3235
3336
|
*
|
|
3236
|
-
* @
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
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
|
-
*
|
|
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 {
|
|
3248
|
-
* @
|
|
3353
|
+
* @param {RTEListBlock} currentBlock - Current list item block.
|
|
3354
|
+
* @param {RTEListItemBlock[]} childBlocks - Current list blocks.
|
|
3249
3355
|
*/
|
|
3250
|
-
|
|
3251
|
-
|
|
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
|
-
*
|
|
3360
|
+
* Should continue process to child elements.
|
|
3267
3361
|
*
|
|
3268
|
-
* @returns {
|
|
3362
|
+
* @returns {boolean} - boolean.
|
|
3269
3363
|
*/
|
|
3270
|
-
|
|
3271
|
-
return
|
|
3364
|
+
shouldProceedToElementChildren() {
|
|
3365
|
+
return true;
|
|
3272
3366
|
}
|
|
3273
3367
|
}
|
|
3274
3368
|
|
|
3275
|
-
/**
|
|
3276
|
-
|
|
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
|
|
3372
|
+
* Can be handle.
|
|
3281
3373
|
*
|
|
3282
|
-
* @param {HTMLElement}
|
|
3283
|
-
* @
|
|
3374
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3375
|
+
* @param {number} currentIndex - Current element index.
|
|
3376
|
+
* @returns {number} - can be handled element count.
|
|
3284
3377
|
*/
|
|
3285
|
-
|
|
3286
|
-
return ['
|
|
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
|
-
*
|
|
3384
|
+
* Parse to a text block.
|
|
3290
3385
|
*
|
|
3291
|
-
* @
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
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
|
-
*
|
|
3322
|
-
*
|
|
3323
|
-
* @returns {HTMLElement} - Block element for child nodes.
|
|
3402
|
+
* Append child blocks.
|
|
3324
3403
|
*/
|
|
3325
|
-
|
|
3326
|
-
|
|
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
|
-
*
|
|
3407
|
+
* Should continue process to child elements.
|
|
3336
3408
|
*
|
|
3337
|
-
* @
|
|
3338
|
-
* @returns {boolean} Result.
|
|
3409
|
+
* @returns {boolean} - boolean.
|
|
3339
3410
|
*/
|
|
3340
|
-
|
|
3341
|
-
return
|
|
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 -
|
|
3347
|
-
* @returns {string} type.
|
|
3417
|
+
* @param {HTMLElement} element - element.
|
|
3418
|
+
* @returns {string} - node type.
|
|
3348
3419
|
*/
|
|
3349
|
-
|
|
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
|
-
*
|
|
3453
|
+
* Can be handle.
|
|
3366
3454
|
*
|
|
3367
|
-
* @
|
|
3455
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3456
|
+
* @param {number} currentIndex - Current element index.
|
|
3457
|
+
* @returns {number} - can be handled element count.
|
|
3368
3458
|
*/
|
|
3369
|
-
|
|
3370
|
-
return
|
|
3459
|
+
canHandle(elementsArray, currentIndex) {
|
|
3460
|
+
return elementsArray[currentIndex].tagName === 'IMG' ? 1 : 0;
|
|
3371
3461
|
}
|
|
3372
3462
|
/**
|
|
3373
|
-
*
|
|
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 {
|
|
3379
|
-
* @returns {RTEContentBlock
|
|
3380
|
-
*/
|
|
3381
|
-
handle(
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
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
|
-
*
|
|
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 {
|
|
3496
|
+
* @returns {boolean} - boolean.
|
|
3400
3497
|
*/
|
|
3401
|
-
|
|
3402
|
-
return
|
|
3498
|
+
shouldProceedToElementChildren() {
|
|
3499
|
+
return false;
|
|
3403
3500
|
}
|
|
3404
3501
|
}
|
|
3405
3502
|
|
|
3406
|
-
/**
|
|
3407
|
-
|
|
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
|
|
3506
|
+
* Can be handle.
|
|
3412
3507
|
*
|
|
3413
|
-
* @param {HTMLElement}
|
|
3414
|
-
* @
|
|
3508
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3509
|
+
* @param {number} currentIndex - Current element index.
|
|
3510
|
+
* @returns {number} - can be handled element count.
|
|
3415
3511
|
*/
|
|
3416
|
-
|
|
3417
|
-
return
|
|
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
|
-
*
|
|
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 {
|
|
3550
|
+
* @returns {boolean} - boolean.
|
|
3424
3551
|
*/
|
|
3425
|
-
|
|
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
|
-
*
|
|
3560
|
+
* Can be handle.
|
|
3430
3561
|
*
|
|
3431
|
-
* @param {
|
|
3432
|
-
* @
|
|
3562
|
+
* @param {HTMLElement[]} elementsArray - Current elements.
|
|
3563
|
+
* @param {number} currentIndex - Current element index.
|
|
3564
|
+
* @returns {number} - can be handled element count.
|
|
3433
3565
|
*/
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
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
|
-
*
|
|
3596
|
+
* Should continue process to child elements.
|
|
3441
3597
|
*
|
|
3442
|
-
* @
|
|
3443
|
-
* @returns {Nullable<HTMLElement>} - blockElement.
|
|
3598
|
+
* @returns {boolean} - boolean.
|
|
3444
3599
|
*/
|
|
3445
|
-
|
|
3446
|
-
return
|
|
3600
|
+
shouldProceedToElementChildren() {
|
|
3601
|
+
return true;
|
|
3447
3602
|
}
|
|
3448
3603
|
}
|
|
3449
3604
|
|
|
3450
|
-
/**
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
3470
|
-
* @returns {RTEContentBlock[]} Block DTO.
|
|
3656
|
+
* @returns {boolean} - boolean.
|
|
3471
3657
|
*/
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
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
|
|
3678
|
+
* Transform process.
|
|
3479
3679
|
*
|
|
3480
|
-
* @param {HTMLElement[]} elements -
|
|
3481
|
-
* @
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
const
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
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
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
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
|
|
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
|
|
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.
|