@elementor/editor-elements 4.3.0-1041 → 4.3.0-1043

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.
@@ -0,0 +1,32 @@
1
+ import { getContainer } from './get-container';
2
+
3
+ type ExtendedWindow = Window & {
4
+ elementor?: {
5
+ getPreviewContainer?: () => { view?: { el?: HTMLElement } } | undefined;
6
+ };
7
+ };
8
+
9
+ export function getPreviewElementDOM( id: string ): HTMLElement | null {
10
+ try {
11
+ const fromContainer = getContainer( id )?.view?.el;
12
+
13
+ if ( fromContainer ) {
14
+ return fromContainer;
15
+ }
16
+
17
+ return queryPreviewDOMByElementId( id );
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+
23
+ function queryPreviewDOMByElementId( id: string ): HTMLElement | null {
24
+ const previewDocument = ( window as unknown as ExtendedWindow ).elementor?.getPreviewContainer?.()?.view?.el
25
+ ?.ownerDocument;
26
+
27
+ if ( ! previewDocument ) {
28
+ return null;
29
+ }
30
+
31
+ return previewDocument.querySelector< HTMLElement >( `[data-id="${ id }"]` );
32
+ }
@@ -0,0 +1,59 @@
1
+ import { getContainer } from '../sync/get-container';
2
+ import { getPreviewElementDOM } from '../sync/get-preview-element-dom';
3
+ import { type V1Element } from '../sync/types';
4
+
5
+ export const DEFAULT_STYLE_CLASS_PREFIX = 'e-default-';
6
+
7
+ export function parseDefaultStyleTagFromClassList( classList: DOMTokenList ): string | null {
8
+ for ( const className of classList ) {
9
+ if ( className.startsWith( DEFAULT_STYLE_CLASS_PREFIX ) ) {
10
+ return className.slice( DEFAULT_STYLE_CLASS_PREFIX.length );
11
+ }
12
+ }
13
+
14
+ return null;
15
+ }
16
+
17
+ export function getDefaultStyleTagFromPreviewElement( elementId: string ): string | null {
18
+ const renderRoot = getAtomicElementRenderRoot( elementId );
19
+
20
+ if ( ! renderRoot ) {
21
+ return null;
22
+ }
23
+
24
+ return parseDefaultStyleTagFromClassList( renderRoot.classList );
25
+ }
26
+
27
+ function getAtomicElementRenderRoot( elementId: string ): HTMLElement | null {
28
+ const view = getContainerView( elementId );
29
+
30
+ if ( view?.getDomElement ) {
31
+ const domElement = view.getDomElement().get?.( 0 );
32
+
33
+ if ( domElement ) {
34
+ return domElement;
35
+ }
36
+ }
37
+
38
+ const wrapper = view?.el ?? getPreviewElementDOM( elementId );
39
+
40
+ if ( ! wrapper ) {
41
+ return null;
42
+ }
43
+
44
+ if ( wrapper.hasAttribute( 'data-id' ) ) {
45
+ return wrapper;
46
+ }
47
+
48
+ const firstChild = wrapper.firstElementChild;
49
+
50
+ if ( firstChild instanceof HTMLElement ) {
51
+ return firstChild;
52
+ }
53
+
54
+ return wrapper;
55
+ }
56
+
57
+ function getContainerView( elementId: string ): V1Element[ 'view' ] | null {
58
+ return getContainer( elementId )?.view ?? null;
59
+ }