@elementor/editor-elements 4.3.0-999 → 4.3.0-beta1

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.
@@ -1,8 +1,7 @@
1
1
  import { type LinkPropValue } from '@elementor/editor-props';
2
2
 
3
- import { getContainer } from './sync/get-container';
4
3
  import { getElementSetting } from './sync/get-element-setting';
5
- import { type ExtendedWindow } from './sync/types';
4
+ import { getPreviewElementDOM } from './sync/get-preview-element-dom';
6
5
 
7
6
  const ANCHOR_SELECTOR = 'a, [data-action-link]';
8
7
 
@@ -144,32 +143,7 @@ function checkForInlineLink( elementId: string, resolvedValue?: LinkValue ): boo
144
143
  }
145
144
 
146
145
  function getElementDOM( id: string ) {
147
- try {
148
- const fromContainer = getContainer( id )?.view?.el;
149
-
150
- if ( fromContainer ) {
151
- return fromContainer;
152
- }
153
-
154
- // Inner elements of component instances are rendered from Twig and have
155
- // no V1 Backbone view, so getContainer(id) returns null. Fall back to
156
- // querying the preview iframe document directly so link-in-link
157
- // restriction still works for those elements.
158
- return queryPreviewDOMByElementId( id );
159
- } catch {
160
- return null;
161
- }
162
- }
163
-
164
- function queryPreviewDOMByElementId( id: string ): HTMLElement | null {
165
- const previewDocument = ( window as unknown as ExtendedWindow ).elementor?.getPreviewContainer?.()?.view?.el
166
- ?.ownerDocument;
167
-
168
- if ( ! previewDocument ) {
169
- return null;
170
- }
171
-
172
- return previewDocument.querySelector< HTMLElement >( `[data-id="${ id }"]` );
146
+ return getPreviewElementDOM( id );
173
147
  }
174
148
 
175
149
  function isElementorElement( element: Element ): boolean {
@@ -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
+ }
package/src/sync/types.ts CHANGED
@@ -182,6 +182,7 @@ export type V1ElementEditorSettingsProps = {
182
182
  initial_position?: number;
183
183
  component_uid?: string;
184
184
  grid_outline?: boolean;
185
+ empty_state_preview?: boolean;
185
186
  };
186
187
 
187
188
  export type V1ElementSettingsProps = Record< string, PropValue >;
@@ -208,6 +209,8 @@ export type V1ElementConfig< T = object, TChild = unknown > = {
208
209
  default_children?: Array< Record< string, TChild > >;
209
210
  children_dependencies?: ChildDependencyRule[];
210
211
  meta?: { [ key: string ]: string | number | boolean | null | NonNullable< V1ElementConfig[ 'meta' ] > };
212
+ default_html_tag?: string;
213
+ html_tag_follows_link?: boolean;
211
214
  } & T;
212
215
 
213
216
  type V1Model< T > = {
@@ -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
+ }