@elementor/editor-components 4.2.0-934 → 4.2.0-936

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-components",
3
3
  "description": "Elementor editor components",
4
- "version": "4.2.0-934",
4
+ "version": "4.2.0-936",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,32 +40,31 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor": "4.2.0-934",
44
- "@elementor/editor-canvas": "4.2.0-934",
45
- "@elementor/editor-controls": "4.2.0-934",
46
- "@elementor/editor-documents": "4.2.0-934",
47
- "@elementor/editor-editing-panel": "4.2.0-934",
48
- "@elementor/editor-elements": "4.2.0-934",
49
- "@elementor/editor-elements-panel": "4.2.0-934",
50
- "@elementor/editor-global-classes": "4.2.0-934",
51
- "@elementor/editor-mcp": "4.2.0-934",
52
- "@elementor/editor-templates": "4.2.0-934",
53
- "@elementor/editor-panels": "4.2.0-934",
54
- "@elementor/editor-props": "4.2.0-934",
55
- "@elementor/editor-styles-repository": "4.2.0-934",
56
- "@elementor/editor-ui": "4.2.0-934",
57
- "@elementor/editor-v1-adapters": "4.2.0-934",
58
- "@elementor/http-client": "4.2.0-934",
43
+ "@elementor/editor": "4.2.0-936",
44
+ "@elementor/editor-canvas": "4.2.0-936",
45
+ "@elementor/editor-controls": "4.2.0-936",
46
+ "@elementor/editor-documents": "4.2.0-936",
47
+ "@elementor/editor-editing-panel": "4.2.0-936",
48
+ "@elementor/editor-elements": "4.2.0-936",
49
+ "@elementor/editor-elements-panel": "4.2.0-936",
50
+ "@elementor/editor-mcp": "4.2.0-936",
51
+ "@elementor/editor-templates": "4.2.0-936",
52
+ "@elementor/editor-panels": "4.2.0-936",
53
+ "@elementor/editor-props": "4.2.0-936",
54
+ "@elementor/editor-ui": "4.2.0-936",
55
+ "@elementor/editor-v1-adapters": "4.2.0-936",
56
+ "@elementor/http-client": "4.2.0-936",
59
57
  "@elementor/icons": "~1.75.1",
60
- "@elementor/events": "4.2.0-934",
61
- "@elementor/query": "4.2.0-934",
62
- "@elementor/schema": "4.2.0-934",
63
- "@elementor/store": "4.2.0-934",
58
+ "@elementor/events": "4.2.0-936",
59
+ "@elementor/query": "4.2.0-936",
60
+ "@elementor/schema": "4.2.0-936",
61
+ "@elementor/store": "4.2.0-936",
64
62
  "@elementor/ui": "1.37.5",
65
- "@elementor/utils": "4.2.0-934",
63
+ "@elementor/utils": "4.2.0-936",
66
64
  "@wordpress/i18n": "^5.13.0",
67
- "@elementor/editor-notifications": "4.2.0-934",
68
- "@elementor/editor-current-user": "4.2.0-934"
65
+ "@elementor/editor-notifications": "4.2.0-936",
66
+ "@elementor/editor-current-user": "4.2.0-936",
67
+ "@elementor/editor-embedded-documents-manager": "4.2.0-936"
69
68
  },
70
69
  "peerDependencies": {
71
70
  "react": "^18.3.1",
package/src/index.ts CHANGED
@@ -77,7 +77,6 @@ export type {
77
77
  OverridableProps,
78
78
  OverridablePropsGroup,
79
79
  PublishedComponent,
80
- StylesDefinition,
81
80
  UnpublishedComponent,
82
81
  UpdatedComponentName,
83
82
  } from './types';
package/src/init.ts CHANGED
@@ -8,7 +8,7 @@ import { getV1CurrentDocument } from '@elementor/editor-documents';
8
8
  import { registerEditingPanelReplacement } from '@elementor/editor-editing-panel';
9
9
  import { type V1ElementData } from '@elementor/editor-elements';
10
10
  import { injectTab } from '@elementor/editor-elements-panel';
11
- import { stylesRepository } from '@elementor/editor-styles-repository';
11
+ import { embeddedDocumentsManager } from '@elementor/editor-embedded-documents-manager';
12
12
  import { registerDataHook } from '@elementor/editor-v1-adapters';
13
13
  import { __registerSlice as registerSlice } from '@elementor/store';
14
14
  import { __ } from '@wordpress/i18n';
@@ -26,15 +26,12 @@ import { PopulateStore } from './populate-store';
26
26
  import { initCircularNestingPrevention } from './prevent-circular-nesting';
27
27
  import { loadComponentsAssets } from './store/actions/load-components-assets';
28
28
  import { removeComponentStyles } from './store/actions/remove-component-styles';
29
- import { componentsStylesProvider } from './store/components-styles-provider';
30
29
  import { slice } from './store/store';
31
30
  import { beforeSave } from './sync/before-save';
32
31
  import { initLoadComponentDataAfterInstanceAdded } from './sync/load-component-data-after-instance-added';
33
32
  import { type ExtendedWindow } from './types';
34
33
 
35
34
  export function init() {
36
- stylesRepository.register( componentsStylesProvider );
37
-
38
35
  registerSlice( slice );
39
36
 
40
37
  registerElementType( COMPONENT_WIDGET_TYPE, ( options: CreateTemplatedElementTypeOptions ) =>
@@ -59,14 +56,20 @@ export function init() {
59
56
  component: PopulateStore,
60
57
  } );
61
58
 
62
- registerDataHook( 'after', 'editor/documents/attach-preview', async () => {
63
- const { id, config } = getV1CurrentDocument();
59
+ registerDataHook( 'after', 'editor/documents/attach-preview', () => {
60
+ const { id, config } = getV1CurrentDocument() ?? {};
64
61
 
65
- if ( id ) {
66
- removeComponentStyles( id );
62
+ if ( ! id ) {
63
+ return;
67
64
  }
68
65
 
69
- await loadComponentsAssets( ( config?.elements as V1ElementData[] ) ?? [] );
66
+ removeComponentStyles( id );
67
+
68
+ void loadComponentsAssets( ( config?.elements as V1ElementData[] ) ?? [] );
69
+ } );
70
+
71
+ embeddedDocumentsManager.onDocumentLoad( ( _documentId, data ) => {
72
+ void loadComponentsAssets( data.elements ?? [] );
70
73
  } );
71
74
 
72
75
  injectIntoLogic( {
@@ -1,15 +1,17 @@
1
1
  import { isDocumentDirty, setDocumentModifiedStatus } from '@elementor/editor-documents';
2
2
  import { type V1ElementData } from '@elementor/editor-elements';
3
+ import { embeddedDocumentsManager } from '@elementor/editor-embedded-documents-manager';
3
4
 
4
5
  import { type ComponentDocumentsMap, getComponentDocuments } from '../../utils/get-component-documents';
5
6
  import { loadComponentsOverridableProps } from './load-components-overridable-props';
6
- import { loadComponentsStyles } from './load-components-styles';
7
7
 
8
8
  export async function loadComponentsAssets( elements: V1ElementData[] ) {
9
- const documents = await getComponentDocuments( elements );
9
+ const documents = await getComponentDocuments( { elements, isRecursive: false } );
10
10
 
11
11
  updateDocumentState( documents );
12
- loadComponentsStyles( documents );
12
+ documents.forEach( ( document, id ) => {
13
+ embeddedDocumentsManager.setDocument( id, document );
14
+ } );
13
15
 
14
16
  await loadComponentsOverridableProps( [ ...documents.keys() ] );
15
17
  }
@@ -1,9 +1,5 @@
1
- import { __dispatch as dispatch } from '@elementor/store';
2
-
3
1
  import { apiClient } from '../../api';
4
- import { slice } from '../store';
5
2
 
6
3
  export function removeComponentStyles( id: number ) {
7
4
  apiClient.invalidateComponentConfigCache( id );
8
- dispatch( slice.actions.removeStyles( { id } ) );
9
5
  }
@@ -24,12 +24,6 @@ export const componentsActions = {
24
24
  resetUnpublished() {
25
25
  dispatch( slice.actions.resetUnpublished() );
26
26
  },
27
- removeStyles( id: ComponentId ) {
28
- dispatch( slice.actions.removeStyles( { id } ) );
29
- },
30
- addStyles( styles: Record< string, unknown > ) {
31
- dispatch( slice.actions.addStyles( styles ) );
32
- },
33
27
  addCreatedThisSession( uid: string ) {
34
28
  dispatch( slice.actions.addCreatedThisSession( uid ) );
35
29
  },
@@ -65,14 +65,6 @@ const baseSlice = createSlice( {
65
65
  resetUnpublished: ( state ) => {
66
66
  state.unpublishedData = [];
67
67
  },
68
- removeStyles( state, { payload }: PayloadAction< { id: ComponentId } > ) {
69
- const { [ payload.id ]: _, ...rest } = state.styles;
70
-
71
- state.styles = rest;
72
- },
73
- addStyles: ( state, { payload } ) => {
74
- state.styles = { ...state.styles, ...payload };
75
- },
76
68
  addCreatedThisSession: ( state, { payload }: PayloadAction< string > ) => {
77
69
  state.createdThisSession.push( payload );
78
70
  },
@@ -1,12 +1,6 @@
1
1
  import { type V1Document } from '@elementor/editor-documents';
2
2
 
3
- import {
4
- type Component,
5
- type ComponentId,
6
- type PublishedComponent,
7
- type StylesDefinition,
8
- type UnpublishedComponent,
9
- } from '../types';
3
+ import { type Component, type ComponentId, type PublishedComponent, type UnpublishedComponent } from '../types';
10
4
 
11
5
  export type SanitizeAttributes = 'overridableProps';
12
6
 
@@ -14,7 +8,6 @@ export type ComponentsState = {
14
8
  data: PublishedComponent[];
15
9
  unpublishedData: UnpublishedComponent[];
16
10
  loadStatus: 'idle' | 'pending' | 'error';
17
- styles: StylesDefinition;
18
11
  createdThisSession: Component[ 'uid' ][];
19
12
  archivedThisSession: ComponentId[];
20
13
  path: ComponentsPathItem[];
@@ -36,7 +29,6 @@ export const initialState: ComponentsState = {
36
29
  data: [],
37
30
  unpublishedData: [],
38
31
  loadStatus: 'idle',
39
- styles: {},
40
32
  createdThisSession: [],
41
33
  archivedThisSession: [],
42
34
  path: [],
@@ -13,7 +13,6 @@ export { initialState, SLICE_NAME } from './store-types';
13
13
  export const selectData = ( state: ComponentsSlice ) => state[ SLICE_NAME ].data;
14
14
  export const selectArchivedThisSession = ( state: ComponentsSlice ) => state[ SLICE_NAME ].archivedThisSession;
15
15
  const selectLoadStatus = ( state: ComponentsSlice ) => state[ SLICE_NAME ].loadStatus;
16
- const selectStylesDefinitions = ( state: ComponentsSlice ) => state[ SLICE_NAME ].styles ?? {};
17
16
  const selectUnpublishedData = ( state: ComponentsSlice ) => state[ SLICE_NAME ].unpublishedData;
18
17
  const getCreatedThisSession = ( state: ComponentsSlice ) => state[ SLICE_NAME ].createdThisSession;
19
18
  const getPath = ( state: ComponentsSlice ) => state[ SLICE_NAME ].path;
@@ -46,21 +45,6 @@ export const selectUnpublishedComponents = createSelector(
46
45
  );
47
46
  export const selectLoadIsPending = createSelector( selectLoadStatus, ( status ) => status === 'pending' );
48
47
  export const selectLoadIsError = createSelector( selectLoadStatus, ( status ) => status === 'error' );
49
- export const selectStyles = ( state: ComponentsSlice ) => state[ SLICE_NAME ].styles ?? {};
50
- export const selectFlatStyles = createSelector(
51
- selectStylesDefinitions,
52
- ( _state: ComponentsSlice, excludeComponentId: ComponentId | null = null ) => excludeComponentId,
53
- ( data, excludeComponentId ) => {
54
- if ( excludeComponentId === null ) {
55
- return Object.values( data ).flat();
56
- }
57
-
58
- return Object.entries( data )
59
- .filter( ( [ id ] ) => id !== String( excludeComponentId ) )
60
- .map( ( [ , styles ] ) => styles )
61
- .flat();
62
- }
63
- );
64
48
  export const selectCreatedThisSession = createSelector(
65
49
  getCreatedThisSession,
66
50
  ( createdThisSession ) => createdThisSession
@@ -22,7 +22,7 @@ export async function publishDraftComponentsInPageBeforeSave( { status, elements
22
22
  return;
23
23
  }
24
24
 
25
- const documents = await getComponentDocuments( elements );
25
+ const documents = await getComponentDocuments( { elements } );
26
26
 
27
27
  const draftIds = [ ...documents.values() ].filter( isDocumentDirty ).map( ( document ) => document.id );
28
28
 
package/src/types.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { type RenderContext } from '@elementor/editor-canvas';
2
2
  import { type V1Element, type V1ElementData } from '@elementor/editor-elements';
3
3
  import { type PropValue, type TransformablePropValue } from '@elementor/editor-props';
4
- import type { StyleDefinition } from '@elementor/editor-styles';
5
4
 
6
5
  export type ComponentFormValues = {
7
6
  componentName: string;
@@ -9,8 +8,6 @@ export type ComponentFormValues = {
9
8
 
10
9
  export type ComponentId = number;
11
10
 
12
- export type StylesDefinition = Record< ComponentId, StyleDefinition[] >;
13
-
14
11
  export type Component = PublishedComponent | UnpublishedComponent;
15
12
 
16
13
  export type PublishedComponent = BaseComponent & {
@@ -9,16 +9,26 @@ export type ComponentDocumentsMap = Map< number, Document >;
9
9
 
10
10
  type ProcessedCache = Map< number, Promise< Document | null > >;
11
11
 
12
- export async function getComponentDocuments(
13
- elements: V1ElementData[],
14
- cache: ProcessedCache = new Map()
15
- ): Promise< ComponentDocumentsMap > {
16
- const componentIds = await getComponentIds( elements, cache );
12
+ type GetterParams = {
13
+ elements: V1ElementData[];
14
+ cache?: ProcessedCache;
15
+ isRecursive?: boolean;
16
+ };
17
+ export async function getComponentDocuments( {
18
+ elements,
19
+ cache = new Map(),
20
+ isRecursive = true,
21
+ }: GetterParams ): Promise< ComponentDocumentsMap > {
22
+ const componentIds = await getComponentIds( elements, cache, isRecursive );
17
23
 
18
24
  return getDocumentsMap( componentIds, cache );
19
25
  }
20
26
 
21
- async function getComponentIds( elements: V1ElementData[], cache: ProcessedCache ): Promise< number[] > {
27
+ async function getComponentIds(
28
+ elements: V1ElementData[],
29
+ cache: ProcessedCache,
30
+ isRecursive: boolean
31
+ ): Promise< number[] > {
22
32
  const results = await Promise.all(
23
33
  elements.map( async ( { widgetType, elType, elements: childElements, settings } ) => {
24
34
  const ids: number[] = [];
@@ -41,8 +51,8 @@ async function getComponentIds( elements: V1ElementData[], cache: ProcessedCache
41
51
  childElements = doc?.elements;
42
52
  }
43
53
 
44
- if ( childElements?.length ) {
45
- const childIds = await getComponentIds( childElements, cache );
54
+ if ( isRecursive && childElements?.length ) {
55
+ const childIds = await getComponentIds( childElements, cache, isRecursive );
46
56
  ids.push( ...childIds );
47
57
  }
48
58
 
@@ -1,50 +0,0 @@
1
- import { type Document } from '@elementor/editor-documents';
2
- import { type V1ElementData } from '@elementor/editor-elements';
3
- import { addDocumentClasses } from '@elementor/editor-global-classes';
4
- import { type StyleDefinition } from '@elementor/editor-styles';
5
- import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
6
-
7
- import { type ComponentDocumentsMap } from '../../utils/get-component-documents';
8
- import { selectStyles, slice } from '../store';
9
-
10
- export function loadComponentsStyles( documents: ComponentDocumentsMap ) {
11
- if ( ! documents.size ) {
12
- return;
13
- }
14
-
15
- const knownComponents = selectStyles( getState() );
16
- const unknownDocuments = new Map( [ ...documents.entries() ].filter( ( [ id ] ) => ! knownComponents[ id ] ) );
17
-
18
- if ( ! unknownDocuments.size ) {
19
- return;
20
- }
21
-
22
- addStyles( unknownDocuments );
23
- }
24
-
25
- function addStyles( documents: ComponentDocumentsMap ) {
26
- const styles = Object.fromEntries(
27
- [ ...documents.entries() ].map( ( [ id, document ] ) => {
28
- addDocumentClasses( id );
29
-
30
- return [ id, extractStylesFromDocument( document ) ];
31
- } )
32
- );
33
-
34
- dispatch( slice.actions.addStyles( styles ) );
35
- }
36
-
37
- function extractStylesFromDocument( document: Document ): Array< StyleDefinition > {
38
- if ( ! document.elements?.length ) {
39
- return [];
40
- }
41
-
42
- return document.elements.flatMap( extractStylesFromElement );
43
- }
44
-
45
- function extractStylesFromElement( element: V1ElementData ): Array< StyleDefinition > {
46
- return [
47
- ...Object.values( element.styles ?? {} ),
48
- ...( element.elements ?? [] ).flatMap( extractStylesFromElement ),
49
- ];
50
- }
@@ -1,26 +0,0 @@
1
- import { getCurrentDocumentId } from '@elementor/editor-elements';
2
- import { createStylesProvider } from '@elementor/editor-styles-repository';
3
- import { __getState as getState, __subscribeWithSelector as subscribeWithSelector } from '@elementor/store';
4
-
5
- import { selectFlatStyles, SLICE_NAME } from './store';
6
-
7
- export const componentsStylesProvider = createStylesProvider( {
8
- key: 'components-styles',
9
- priority: 100,
10
- subscribe: ( cb ) =>
11
- subscribeWithSelector(
12
- ( state ) => state[ SLICE_NAME ],
13
- () => {
14
- cb();
15
- }
16
- ),
17
- actions: {
18
- all: () => {
19
- const currentDocumentId = getCurrentDocumentId();
20
- return selectFlatStyles( getState(), currentDocumentId );
21
- },
22
- get: ( id ) => {
23
- return selectFlatStyles( getState() ).find( ( style ) => style.id === id ) ?? null;
24
- },
25
- },
26
- } );