@elementor/editor-components 4.2.0-935 → 4.2.0-937
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 +1 -13
- package/dist/index.d.ts +1 -13
- package/dist/index.js +34 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -24
- package/src/index.ts +0 -1
- package/src/init.ts +12 -9
- package/src/store/actions/load-components-assets.ts +5 -3
- package/src/store/actions/remove-component-styles.ts +0 -4
- package/src/store/dispatchers.ts +0 -6
- package/src/store/extensible-slice.ts +0 -8
- package/src/store/store-types.ts +1 -9
- package/src/store/store.ts +0 -16
- package/src/sync/publish-draft-components-in-page-before-save.ts +1 -1
- package/src/types.ts +0 -3
- package/src/utils/get-component-documents.ts +18 -8
- package/src/store/actions/load-components-styles.ts +0 -50
- package/src/store/components-styles-provider.ts +0 -26
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-
|
|
4
|
+
"version": "4.2.0-937",
|
|
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-
|
|
44
|
-
"@elementor/editor-canvas": "4.2.0-
|
|
45
|
-
"@elementor/editor-controls": "4.2.0-
|
|
46
|
-
"@elementor/editor-documents": "4.2.0-
|
|
47
|
-
"@elementor/editor-editing-panel": "4.2.0-
|
|
48
|
-
"@elementor/editor-elements": "4.2.0-
|
|
49
|
-
"@elementor/editor-elements-panel": "4.2.0-
|
|
50
|
-
"@elementor/editor-
|
|
51
|
-
"@elementor/editor-
|
|
52
|
-
"@elementor/editor-
|
|
53
|
-
"@elementor/editor-
|
|
54
|
-
"@elementor/editor-
|
|
55
|
-
"@elementor/editor-
|
|
56
|
-
"@elementor/
|
|
57
|
-
"@elementor/editor-v1-adapters": "4.2.0-935",
|
|
58
|
-
"@elementor/http-client": "4.2.0-935",
|
|
43
|
+
"@elementor/editor": "4.2.0-937",
|
|
44
|
+
"@elementor/editor-canvas": "4.2.0-937",
|
|
45
|
+
"@elementor/editor-controls": "4.2.0-937",
|
|
46
|
+
"@elementor/editor-documents": "4.2.0-937",
|
|
47
|
+
"@elementor/editor-editing-panel": "4.2.0-937",
|
|
48
|
+
"@elementor/editor-elements": "4.2.0-937",
|
|
49
|
+
"@elementor/editor-elements-panel": "4.2.0-937",
|
|
50
|
+
"@elementor/editor-mcp": "4.2.0-937",
|
|
51
|
+
"@elementor/editor-templates": "4.2.0-937",
|
|
52
|
+
"@elementor/editor-panels": "4.2.0-937",
|
|
53
|
+
"@elementor/editor-props": "4.2.0-937",
|
|
54
|
+
"@elementor/editor-ui": "4.2.0-937",
|
|
55
|
+
"@elementor/editor-v1-adapters": "4.2.0-937",
|
|
56
|
+
"@elementor/http-client": "4.2.0-937",
|
|
59
57
|
"@elementor/icons": "~1.75.1",
|
|
60
|
-
"@elementor/events": "4.2.0-
|
|
61
|
-
"@elementor/query": "4.2.0-
|
|
62
|
-
"@elementor/schema": "4.2.0-
|
|
63
|
-
"@elementor/store": "4.2.0-
|
|
58
|
+
"@elementor/events": "4.2.0-937",
|
|
59
|
+
"@elementor/query": "4.2.0-937",
|
|
60
|
+
"@elementor/schema": "4.2.0-937",
|
|
61
|
+
"@elementor/store": "4.2.0-937",
|
|
64
62
|
"@elementor/ui": "1.37.5",
|
|
65
|
-
"@elementor/utils": "4.2.0-
|
|
63
|
+
"@elementor/utils": "4.2.0-937",
|
|
66
64
|
"@wordpress/i18n": "^5.13.0",
|
|
67
|
-
"@elementor/editor-notifications": "4.2.0-
|
|
68
|
-
"@elementor/editor-current-user": "4.2.0-
|
|
65
|
+
"@elementor/editor-notifications": "4.2.0-937",
|
|
66
|
+
"@elementor/editor-current-user": "4.2.0-937",
|
|
67
|
+
"@elementor/editor-embedded-documents-manager": "4.2.0-937"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
70
|
"react": "^18.3.1",
|
package/src/index.ts
CHANGED
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 {
|
|
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',
|
|
63
|
-
const { id, config } = getV1CurrentDocument();
|
|
59
|
+
registerDataHook( 'after', 'editor/documents/attach-preview', () => {
|
|
60
|
+
const { id, config } = getV1CurrentDocument() ?? {};
|
|
64
61
|
|
|
65
|
-
if ( id ) {
|
|
66
|
-
|
|
62
|
+
if ( ! id ) {
|
|
63
|
+
return;
|
|
67
64
|
}
|
|
68
65
|
|
|
69
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/store/dispatchers.ts
CHANGED
|
@@ -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
|
},
|
package/src/store/store-types.ts
CHANGED
|
@@ -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: [],
|
package/src/store/store.ts
CHANGED
|
@@ -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
|
-
|
|
13
|
-
elements: V1ElementData[]
|
|
14
|
-
cache
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
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
|
-
} );
|