@elementor/editor-props 4.0.0-552 → 4.0.0-573
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/index.d.mts +324 -24
- package/dist/index.d.ts +324 -24
- package/dist/index.js +145 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/prop-types/email.ts +22 -0
- package/src/prop-types/html-v2.ts +30 -0
- package/src/prop-types/index.ts +2 -0
- package/src/prop-types/string-array.ts +4 -3
- package/src/types.ts +1 -0
- package/src/utils/parse-html-children.ts +82 -0
- package/src/utils/prop-dependency-utils.ts +5 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type ChildElement } from '../prop-types/html-v2';
|
|
2
|
+
|
|
3
|
+
export interface ParseResult {
|
|
4
|
+
content: string;
|
|
5
|
+
children: ChildElement[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const INLINE_ELEMENTS = new Set( [ 'span', 'b', 'strong', 'i', 'em', 'u', 'a', 'del', 'sup', 'sub', 's' ] );
|
|
9
|
+
|
|
10
|
+
function generateElementId(): string {
|
|
11
|
+
const timestamp = Date.now().toString( 36 );
|
|
12
|
+
const randomPart = Math.random().toString( 36 ).substring( 2, 9 );
|
|
13
|
+
|
|
14
|
+
return `e-${ timestamp }-${ randomPart }`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function traverseChildren( node: Element ): ChildElement[] {
|
|
18
|
+
const result: ChildElement[] = [];
|
|
19
|
+
|
|
20
|
+
for ( const child of Array.from( node.children ) ) {
|
|
21
|
+
const tagName = child.tagName.toLowerCase();
|
|
22
|
+
|
|
23
|
+
if ( ! INLINE_ELEMENTS.has( tagName ) ) {
|
|
24
|
+
result.push( ...traverseChildren( child ) );
|
|
25
|
+
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let id = child.getAttribute( 'id' );
|
|
30
|
+
|
|
31
|
+
if ( ! id ) {
|
|
32
|
+
id = generateElementId();
|
|
33
|
+
child.setAttribute( 'id', id );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const childElement: ChildElement = {
|
|
37
|
+
id,
|
|
38
|
+
type: tagName,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const textContent = child.textContent?.trim();
|
|
42
|
+
|
|
43
|
+
if ( textContent ) {
|
|
44
|
+
childElement.content = textContent;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const nestedChildren = traverseChildren( child );
|
|
48
|
+
|
|
49
|
+
if ( nestedChildren.length > 0 ) {
|
|
50
|
+
childElement.children = nestedChildren;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
result.push( childElement );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function parseHtmlChildren( html: string ): ParseResult {
|
|
60
|
+
if ( ! html ) {
|
|
61
|
+
return { content: html, children: [] };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const parser = new DOMParser();
|
|
65
|
+
const doc = parser.parseFromString( `<body>${ html }</body>`, 'text/html' );
|
|
66
|
+
|
|
67
|
+
const parserError = doc.querySelector( 'parsererror' );
|
|
68
|
+
|
|
69
|
+
if ( parserError ) {
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
console.warn( 'HTML parsing error, returning original content:', parserError.textContent );
|
|
72
|
+
return { content: html, children: [] };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const body = doc.body;
|
|
76
|
+
const children = traverseChildren( body );
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
content: body.innerHTML,
|
|
80
|
+
children,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -79,7 +79,11 @@ export function evaluateTerm( term: DependencyTerm, actualValue: unknown ) {
|
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const transformedValue = Array.isArray( actualValue )
|
|
83
|
+
? actualValue.map( ( item ) => ( isTransformable( item ) ? item.value : item ) )
|
|
84
|
+
: actualValue;
|
|
85
|
+
|
|
86
|
+
return ( 'contains' === operator ) === transformedValue.includes( valueToCompare as never );
|
|
83
87
|
|
|
84
88
|
case 'exists':
|
|
85
89
|
case 'not_exist':
|