@elementor/editor-components 3.35.0-472 → 3.35.0-474
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.js +66 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -22
- package/src/store/actions/load-components-assets.ts +7 -12
- package/src/store/actions/load-components-styles.ts +22 -21
- package/src/sync/update-components-before-save.ts +4 -9
- package/src/utils/get-component-documents.ts +70 -0
- package/src/utils/get-component-ids.ts +0 -41
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-components",
|
|
3
3
|
"description": "Elementor editor components",
|
|
4
|
-
"version": "3.35.0-
|
|
4
|
+
"version": "3.35.0-474",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,30 +40,30 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor": "3.35.0-
|
|
44
|
-
"@elementor/editor-canvas": "3.35.0-
|
|
45
|
-
"@elementor/editor-controls": "3.35.0-
|
|
46
|
-
"@elementor/editor-documents": "3.35.0-
|
|
47
|
-
"@elementor/editor-editing-panel": "3.35.0-
|
|
48
|
-
"@elementor/editor-elements": "3.35.0-
|
|
49
|
-
"@elementor/editor-elements-panel": "3.35.0-
|
|
50
|
-
"@elementor/editor-mcp": "3.35.0-
|
|
51
|
-
"@elementor/editor-panels": "3.35.0-
|
|
52
|
-
"@elementor/editor-props": "3.35.0-
|
|
53
|
-
"@elementor/editor-styles-repository": "3.35.0-
|
|
54
|
-
"@elementor/editor-ui": "3.35.0-
|
|
55
|
-
"@elementor/editor-v1-adapters": "3.35.0-
|
|
56
|
-
"@elementor/http-client": "3.35.0-
|
|
43
|
+
"@elementor/editor": "3.35.0-474",
|
|
44
|
+
"@elementor/editor-canvas": "3.35.0-474",
|
|
45
|
+
"@elementor/editor-controls": "3.35.0-474",
|
|
46
|
+
"@elementor/editor-documents": "3.35.0-474",
|
|
47
|
+
"@elementor/editor-editing-panel": "3.35.0-474",
|
|
48
|
+
"@elementor/editor-elements": "3.35.0-474",
|
|
49
|
+
"@elementor/editor-elements-panel": "3.35.0-474",
|
|
50
|
+
"@elementor/editor-mcp": "3.35.0-474",
|
|
51
|
+
"@elementor/editor-panels": "3.35.0-474",
|
|
52
|
+
"@elementor/editor-props": "3.35.0-474",
|
|
53
|
+
"@elementor/editor-styles-repository": "3.35.0-474",
|
|
54
|
+
"@elementor/editor-ui": "3.35.0-474",
|
|
55
|
+
"@elementor/editor-v1-adapters": "3.35.0-474",
|
|
56
|
+
"@elementor/http-client": "3.35.0-474",
|
|
57
57
|
"@elementor/icons": "^1.63.0",
|
|
58
|
-
"@elementor/mixpanel": "3.35.0-
|
|
59
|
-
"@elementor/query": "3.35.0-
|
|
60
|
-
"@elementor/schema": "3.35.0-
|
|
61
|
-
"@elementor/store": "3.35.0-
|
|
58
|
+
"@elementor/mixpanel": "3.35.0-474",
|
|
59
|
+
"@elementor/query": "3.35.0-474",
|
|
60
|
+
"@elementor/schema": "3.35.0-474",
|
|
61
|
+
"@elementor/store": "3.35.0-474",
|
|
62
62
|
"@elementor/ui": "1.36.17",
|
|
63
|
-
"@elementor/utils": "3.35.0-
|
|
63
|
+
"@elementor/utils": "3.35.0-474",
|
|
64
64
|
"@wordpress/i18n": "^5.13.0",
|
|
65
|
-
"@elementor/editor-notifications": "3.35.0-
|
|
66
|
-
"@elementor/editor-current-user": "3.35.0-
|
|
65
|
+
"@elementor/editor-notifications": "3.35.0-474",
|
|
66
|
+
"@elementor/editor-current-user": "3.35.0-474"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": "^18.3.1",
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import { isDocumentDirty, setDocumentModifiedStatus } from '@elementor/editor-documents';
|
|
2
2
|
import { type V1ElementData } from '@elementor/editor-elements';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { getComponentIds } from '../../utils/get-component-ids';
|
|
4
|
+
import { type ComponentDocumentsMap, getComponentDocuments } from '../../utils/get-component-documents';
|
|
6
5
|
import { loadComponentsOverridableProps } from './load-components-overridable-props';
|
|
7
6
|
import { loadComponentsStyles } from './load-components-styles';
|
|
8
7
|
|
|
9
8
|
export async function loadComponentsAssets( elements: V1ElementData[] ) {
|
|
10
|
-
const
|
|
9
|
+
const documents = await getComponentDocuments( elements );
|
|
11
10
|
|
|
12
11
|
return Promise.all( [
|
|
13
|
-
updateDocumentState(
|
|
14
|
-
loadComponentsOverridableProps(
|
|
15
|
-
loadComponentsStyles(
|
|
12
|
+
updateDocumentState( documents ),
|
|
13
|
+
loadComponentsOverridableProps( [ ...documents.keys() ] ),
|
|
14
|
+
loadComponentsStyles( documents ),
|
|
16
15
|
] );
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
( document ) => !! document
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const isDrafted = components.some( isDocumentDirty );
|
|
18
|
+
function updateDocumentState( documents: ComponentDocumentsMap ) {
|
|
19
|
+
const isDrafted = [ ...documents.values() ].some( isDocumentDirty );
|
|
25
20
|
|
|
26
21
|
if ( isDrafted ) {
|
|
27
22
|
setDocumentModifiedStatus( true );
|
|
@@ -1,44 +1,45 @@
|
|
|
1
|
+
import { type Document } from '@elementor/editor-documents';
|
|
1
2
|
import { type V1ElementData } from '@elementor/editor-elements';
|
|
2
3
|
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
3
4
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import { type ComponentId } from '../../types';
|
|
6
|
+
import { type ComponentDocumentsMap } from '../../utils/get-component-documents';
|
|
7
7
|
import { selectStyles, slice } from '../store';
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
if ( !
|
|
9
|
+
export function loadComponentsStyles( documents: ComponentDocumentsMap ) {
|
|
10
|
+
if ( ! documents.size ) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const knownComponents = selectStyles( getState() );
|
|
15
|
-
const
|
|
15
|
+
const unknownDocuments = new Map( [ ...documents.entries() ].filter( ( [ id ] ) => ! knownComponents[ id ] ) );
|
|
16
16
|
|
|
17
|
-
if ( !
|
|
17
|
+
if ( ! unknownDocuments.size ) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
addStyles( unknownDocuments );
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
const newComponents = await loadStyles( ids );
|
|
26
|
-
|
|
27
|
-
addStyles( newComponents );
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function loadStyles( ids: number[] ): Promise< [ number, V1ElementData ][] > {
|
|
31
|
-
return Promise.all( ids.map( async ( id ) => [ id, await apiClient.getComponentConfig( id ) ] ) );
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function addStyles( data: ( readonly [ ComponentId, V1ElementData ] )[] ) {
|
|
24
|
+
function addStyles( documents: ComponentDocumentsMap ) {
|
|
35
25
|
const styles = Object.fromEntries(
|
|
36
|
-
|
|
26
|
+
[ ...documents.entries() ].map( ( [ id, document ] ) => [ id, extractStylesFromDocument( document ) ] )
|
|
37
27
|
);
|
|
38
28
|
|
|
39
29
|
dispatch( slice.actions.addStyles( styles ) );
|
|
40
30
|
}
|
|
41
31
|
|
|
42
|
-
function
|
|
43
|
-
|
|
32
|
+
function extractStylesFromDocument( document: Document ): Array< StyleDefinition > {
|
|
33
|
+
if ( ! document.elements?.length ) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return document.elements.flatMap( extractStylesFromElement );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function extractStylesFromElement( element: V1ElementData ): Array< StyleDefinition > {
|
|
41
|
+
return [
|
|
42
|
+
...Object.values( element.styles ?? {} ),
|
|
43
|
+
...( element.elements ?? [] ).flatMap( extractStylesFromElement ),
|
|
44
|
+
];
|
|
44
45
|
}
|
|
@@ -3,8 +3,8 @@ import { type V1ElementData } from '@elementor/editor-elements';
|
|
|
3
3
|
|
|
4
4
|
import { apiClient } from '../api';
|
|
5
5
|
import { type DocumentSaveStatus } from '../types';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { invalidateComponentDocumentData } from '../utils/component-document-data';
|
|
7
|
+
import { getComponentDocuments } from '../utils/get-component-documents';
|
|
8
8
|
|
|
9
9
|
type Options = {
|
|
10
10
|
status: DocumentSaveStatus;
|
|
@@ -16,14 +16,9 @@ export async function updateComponentsBeforeSave( { status, elements }: Options
|
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const documents = await getComponentDocuments( elements );
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const draftIds = componentDocumentData
|
|
24
|
-
.filter( ( document ) => !! document )
|
|
25
|
-
.filter( isDocumentDirty )
|
|
26
|
-
.map( ( document ) => document.id );
|
|
21
|
+
const draftIds = [ ...documents.values() ].filter( isDocumentDirty ).map( ( document ) => document.id );
|
|
27
22
|
|
|
28
23
|
if ( draftIds.length === 0 ) {
|
|
29
24
|
return;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Document } from '@elementor/editor-documents';
|
|
2
|
+
import { type V1ElementData } from '@elementor/editor-elements';
|
|
3
|
+
|
|
4
|
+
import { type ComponentInstanceProp } from '../prop-types/component-instance-prop-type';
|
|
5
|
+
import { getComponentDocumentData } from './component-document-data';
|
|
6
|
+
import { isComponentInstance } from './is-component-instance';
|
|
7
|
+
|
|
8
|
+
export type ComponentDocumentsMap = Map< number, Document >;
|
|
9
|
+
|
|
10
|
+
type ProcessedCache = Map< number, Promise< Document | null > >;
|
|
11
|
+
|
|
12
|
+
export async function getComponentDocuments(
|
|
13
|
+
elements: V1ElementData[],
|
|
14
|
+
cache: ProcessedCache = new Map()
|
|
15
|
+
): Promise< ComponentDocumentsMap > {
|
|
16
|
+
const componentIds = await getComponentIds( elements, cache );
|
|
17
|
+
|
|
18
|
+
return getDocumentsMap( componentIds, cache );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getComponentIds( elements: V1ElementData[], cache: ProcessedCache ): Promise< number[] > {
|
|
22
|
+
const results = await Promise.all(
|
|
23
|
+
elements.map( async ( { widgetType, elType, elements: childElements, settings } ) => {
|
|
24
|
+
const ids: number[] = [];
|
|
25
|
+
|
|
26
|
+
if ( isComponentInstance( { widgetType, elType } ) ) {
|
|
27
|
+
const componentId = ( settings?.component_instance as ComponentInstanceProp )?.value?.component_id
|
|
28
|
+
.value;
|
|
29
|
+
|
|
30
|
+
if ( ! componentId ) {
|
|
31
|
+
return ids;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ids.push( componentId );
|
|
35
|
+
|
|
36
|
+
if ( ! cache.has( componentId ) ) {
|
|
37
|
+
cache.set( componentId, getComponentDocumentData( componentId ) );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const doc = await cache.get( componentId );
|
|
41
|
+
childElements = doc?.elements;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ( childElements?.length ) {
|
|
45
|
+
const childIds = await getComponentIds( childElements, cache );
|
|
46
|
+
ids.push( ...childIds );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return ids;
|
|
50
|
+
} )
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return [ ...new Set( results.flat() ) ];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function getDocumentsMap( ids: number[], cache: ProcessedCache ): Promise< ComponentDocumentsMap > {
|
|
57
|
+
const documents = await Promise.all(
|
|
58
|
+
ids.map( async ( id ) => {
|
|
59
|
+
const document = await cache.get( id );
|
|
60
|
+
|
|
61
|
+
if ( ! document ) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [ id, document ];
|
|
66
|
+
} )
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return new Map( documents.filter( ( document ): document is [ number, Document ] => document !== null ) );
|
|
70
|
+
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
-
|
|
3
|
-
import { type ComponentInstanceProp } from '../prop-types/component-instance-prop-type';
|
|
4
|
-
import { getComponentDocumentData } from './component-document-data';
|
|
5
|
-
import { isComponentInstance } from './is-component-instance';
|
|
6
|
-
|
|
7
|
-
export const getComponentIds = async ( elements: V1ElementData[] ): Promise< number[] > => {
|
|
8
|
-
const components = elements.map( async ( { widgetType, elType, elements: childElements, settings } ) => {
|
|
9
|
-
const ids: number[] = [];
|
|
10
|
-
|
|
11
|
-
const isComponent = isComponentInstance( { widgetType, elType } );
|
|
12
|
-
|
|
13
|
-
if ( isComponent ) {
|
|
14
|
-
const componentId = ( settings?.component_instance as ComponentInstanceProp )?.value?.component_id.value;
|
|
15
|
-
|
|
16
|
-
if ( ! componentId ) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const document = await getComponentDocumentData( componentId );
|
|
21
|
-
|
|
22
|
-
childElements = document?.elements;
|
|
23
|
-
|
|
24
|
-
if ( Boolean( componentId ) ) {
|
|
25
|
-
ids.push( componentId );
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if ( !! childElements?.length ) {
|
|
30
|
-
const newIds = await getComponentIds( childElements );
|
|
31
|
-
|
|
32
|
-
ids.push( ...Array.from( new Set( newIds ) ) );
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return ids;
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
const result = ( await Promise.all( components ) ).flat();
|
|
39
|
-
|
|
40
|
-
return Array.from( new Set( result ) ).filter( ( value ) => value !== undefined );
|
|
41
|
-
};
|