@elementor/editor-components 3.33.0-248 → 3.33.0-250
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 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/api.ts +7 -2
- package/src/component-id-transformer.ts +4 -18
- package/src/init.ts +1 -1
- package/src/store/load-components-styles.ts +1 -1
- package/src/sync/before-save.ts +15 -0
- package/src/{utils/before-save.ts → sync/create-components-before-save.ts} +10 -12
- package/src/sync/update-components-before-save.ts +41 -0
- package/src/types.ts +11 -1
- package/src/utils/component-document-data.ts +47 -0
- package/src/utils/get-component-ids.ts +3 -1
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.33.0-
|
|
4
|
+
"version": "3.33.0-250",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor": "3.33.0-
|
|
44
|
-
"@elementor/editor-canvas": "3.33.0-
|
|
45
|
-
"@elementor/editor-documents": "3.33.0-
|
|
46
|
-
"@elementor/editor-elements": "3.33.0-
|
|
47
|
-
"@elementor/editor-elements-panel": "3.33.0-
|
|
48
|
-
"@elementor/editor-props": "3.33.0-
|
|
49
|
-
"@elementor/editor-styles-repository": "3.33.0-
|
|
50
|
-
"@elementor/editor-ui": "3.33.0-
|
|
51
|
-
"@elementor/editor-v1-adapters": "3.33.0-
|
|
52
|
-
"@elementor/http-client": "3.33.0-
|
|
43
|
+
"@elementor/editor": "3.33.0-250",
|
|
44
|
+
"@elementor/editor-canvas": "3.33.0-250",
|
|
45
|
+
"@elementor/editor-documents": "3.33.0-250",
|
|
46
|
+
"@elementor/editor-elements": "3.33.0-250",
|
|
47
|
+
"@elementor/editor-elements-panel": "3.33.0-250",
|
|
48
|
+
"@elementor/editor-props": "3.33.0-250",
|
|
49
|
+
"@elementor/editor-styles-repository": "3.33.0-250",
|
|
50
|
+
"@elementor/editor-ui": "3.33.0-250",
|
|
51
|
+
"@elementor/editor-v1-adapters": "3.33.0-250",
|
|
52
|
+
"@elementor/http-client": "3.33.0-250",
|
|
53
53
|
"@elementor/icons": "1.53.0",
|
|
54
|
-
"@elementor/query": "3.33.0-
|
|
55
|
-
"@elementor/schema": "3.33.0-
|
|
56
|
-
"@elementor/store": "3.33.0-
|
|
54
|
+
"@elementor/query": "3.33.0-250",
|
|
55
|
+
"@elementor/schema": "3.33.0-250",
|
|
56
|
+
"@elementor/store": "3.33.0-250",
|
|
57
57
|
"@elementor/ui": "1.36.15",
|
|
58
|
-
"@elementor/utils": "3.33.0-
|
|
58
|
+
"@elementor/utils": "3.33.0-250",
|
|
59
59
|
"@wordpress/i18n": "^5.13.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
package/src/api.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type V1ElementData } from '@elementor/editor-elements';
|
|
|
2
2
|
import { ajax } from '@elementor/editor-v1-adapters';
|
|
3
3
|
import { type HttpResponse, httpService } from '@elementor/http-client';
|
|
4
4
|
|
|
5
|
-
import { type Component, type
|
|
5
|
+
import { type Component, type DocumentSaveStatus } from './types';
|
|
6
6
|
|
|
7
7
|
const BASE_URL = 'elementor/v1/components';
|
|
8
8
|
const LOCK_COMPONENT = `${ BASE_URL }/lock`;
|
|
@@ -10,7 +10,7 @@ const UNLOCK_COMPONENT = `${ BASE_URL }/unlock`;
|
|
|
10
10
|
const BASE_URL_LOCK_STATUS = `${ BASE_URL }/lock-status`;
|
|
11
11
|
|
|
12
12
|
export type CreateComponentPayload = {
|
|
13
|
-
status:
|
|
13
|
+
status: DocumentSaveStatus;
|
|
14
14
|
items: Array< {
|
|
15
15
|
temp_id: number;
|
|
16
16
|
title: string;
|
|
@@ -42,6 +42,11 @@ export const apiClient = {
|
|
|
42
42
|
httpService()
|
|
43
43
|
.post< HttpResponse< CreateComponentResponse > >( `${ BASE_URL }`, payload )
|
|
44
44
|
.then( ( res ) => res.data.data ),
|
|
45
|
+
updateStatuses: ( ids: number[], status: DocumentSaveStatus ) =>
|
|
46
|
+
httpService().put( `${ BASE_URL }/status`, {
|
|
47
|
+
ids,
|
|
48
|
+
status,
|
|
49
|
+
} ),
|
|
45
50
|
getComponentConfig: ( id: number ) => ajax.load< { id: number }, V1ElementData >( getParams( id ) ),
|
|
46
51
|
invalidateComponentConfigCache: ( id: number ) => ajax.invalidateCache< { id: number } >( getParams( id ) ),
|
|
47
52
|
getComponentLockStatus: async ( componentId: number ) =>
|
|
@@ -2,32 +2,18 @@ import { createTransformer } from '@elementor/editor-canvas';
|
|
|
2
2
|
import { __getState as getState } from '@elementor/store';
|
|
3
3
|
|
|
4
4
|
import { selectUnpublishedComponents } from './store/store';
|
|
5
|
-
|
|
6
|
-
type ComponentIdTransformerWindow = Window & {
|
|
7
|
-
elementor?: {
|
|
8
|
-
documents?: {
|
|
9
|
-
request: ( id: number ) => Promise< { elements?: unknown[] } >;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
5
|
+
import { getComponentDocumentData } from './utils/component-document-data';
|
|
13
6
|
|
|
14
7
|
export const componentIdTransformer = createTransformer( async ( id: number ) => {
|
|
15
8
|
const unpublishedComponents = selectUnpublishedComponents( getState() );
|
|
16
9
|
|
|
17
10
|
const unpublishedComponent = unpublishedComponents.find( ( component ) => component.id === id );
|
|
11
|
+
|
|
18
12
|
if ( unpublishedComponent ) {
|
|
19
13
|
return structuredClone( unpublishedComponent.elements );
|
|
20
14
|
}
|
|
21
15
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const documentManager = extendedWindow.elementor?.documents;
|
|
25
|
-
|
|
26
|
-
if ( ! documentManager ) {
|
|
27
|
-
throw new Error( 'Elementor documents manager not found' );
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const data = await documentManager.request( id );
|
|
16
|
+
const data = await getComponentDocumentData( id );
|
|
31
17
|
|
|
32
|
-
return data
|
|
18
|
+
return data?.elements ?? [];
|
|
33
19
|
} );
|
package/src/init.ts
CHANGED
|
@@ -23,8 +23,8 @@ import { componentsStylesProvider } from './store/components-styles-provider';
|
|
|
23
23
|
import { loadComponentsStyles } from './store/load-components-styles';
|
|
24
24
|
import { removeComponentStyles } from './store/remove-component-styles';
|
|
25
25
|
import { slice } from './store/store';
|
|
26
|
+
import { beforeSave } from './sync/before-save';
|
|
26
27
|
import { type ExtendedWindow } from './types';
|
|
27
|
-
import { beforeSave } from './utils/before-save';
|
|
28
28
|
|
|
29
29
|
const COMPONENT_DOCUMENT_TYPE = 'elementor_component';
|
|
30
30
|
|
|
@@ -8,7 +8,7 @@ import { getComponentIds } from '../utils/get-component-ids';
|
|
|
8
8
|
import { selectStyles, slice } from './store';
|
|
9
9
|
|
|
10
10
|
export async function loadComponentsStyles( elements: V1ElementData[] ) {
|
|
11
|
-
const componentIds =
|
|
11
|
+
const componentIds = getComponentIds( elements );
|
|
12
12
|
|
|
13
13
|
if ( ! componentIds.length ) {
|
|
14
14
|
return;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Container, type DocumentSaveStatus } from '../types';
|
|
2
|
+
import { createComponentsBeforeSave } from './create-components-before-save';
|
|
3
|
+
import { updateComponentsBeforeSave } from './update-components-before-save';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
container: Container;
|
|
7
|
+
status: DocumentSaveStatus;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const beforeSave = ( { container, status }: Options ) => {
|
|
11
|
+
return Promise.all( [
|
|
12
|
+
createComponentsBeforeSave( { container, status } ),
|
|
13
|
+
updateComponentsBeforeSave( { container, status } ),
|
|
14
|
+
] );
|
|
15
|
+
};
|
|
@@ -4,17 +4,15 @@ import { __dispatch as dispatch, __getState as getState } from '@elementor/store
|
|
|
4
4
|
|
|
5
5
|
import { apiClient } from '../api';
|
|
6
6
|
import { selectUnpublishedComponents, slice, type UnpublishedComponent } from '../store/store';
|
|
7
|
-
import { type
|
|
7
|
+
import { type Container, type DocumentSaveStatus } from '../types';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const beforeSave = async ( { container, status }: { container: Container; status: DocumentStatus } ) => {
|
|
9
|
+
export async function createComponentsBeforeSave( {
|
|
10
|
+
container,
|
|
11
|
+
status,
|
|
12
|
+
}: {
|
|
13
|
+
container: Container;
|
|
14
|
+
status: DocumentSaveStatus;
|
|
15
|
+
} ) {
|
|
18
16
|
const unpublishedComponents = selectUnpublishedComponents( getState() );
|
|
19
17
|
|
|
20
18
|
if ( ! unpublishedComponents.length ) {
|
|
@@ -39,11 +37,11 @@ export const beforeSave = async ( { container, status }: { container: Container;
|
|
|
39
37
|
} catch ( error ) {
|
|
40
38
|
throw new Error( `Failed to publish components and update component instances: ${ error }` );
|
|
41
39
|
}
|
|
42
|
-
}
|
|
40
|
+
}
|
|
43
41
|
|
|
44
42
|
async function createComponents(
|
|
45
43
|
components: UnpublishedComponent[],
|
|
46
|
-
status:
|
|
44
|
+
status: DocumentSaveStatus
|
|
47
45
|
): Promise< Map< number, number > > {
|
|
48
46
|
const response = await apiClient.create( {
|
|
49
47
|
status,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { apiClient } from '../api';
|
|
2
|
+
import { type Container, type DocumentSaveStatus } from '../types';
|
|
3
|
+
import { getComponentDocumentData, invalidateComponentDocumentData } from '../utils/component-document-data';
|
|
4
|
+
import { getComponentIds } from '../utils/get-component-ids';
|
|
5
|
+
|
|
6
|
+
type Options = {
|
|
7
|
+
status: DocumentSaveStatus;
|
|
8
|
+
container: Container;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function updateComponentsBeforeSave( { status, container }: Options ) {
|
|
12
|
+
if ( status !== 'publish' ) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const elements = container.model.get( 'elements' ).toJSON();
|
|
17
|
+
|
|
18
|
+
const componentDocumentData = await Promise.all(
|
|
19
|
+
getComponentIds( elements ).map( ( id ) => getComponentDocumentData( id ) )
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const draftIds = componentDocumentData
|
|
23
|
+
.filter( ( document ) => !! document )
|
|
24
|
+
.filter( ( document ) => {
|
|
25
|
+
const isDraft = document.status.value === 'draft';
|
|
26
|
+
|
|
27
|
+
// When the component is published, but have draft version.
|
|
28
|
+
const hasAutosave = document.revisions.current_id !== document.id;
|
|
29
|
+
|
|
30
|
+
return isDraft || hasAutosave;
|
|
31
|
+
} )
|
|
32
|
+
.map( ( document ) => document.id );
|
|
33
|
+
|
|
34
|
+
if ( draftIds.length === 0 ) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await apiClient.updateStatuses( draftIds, 'publish' );
|
|
39
|
+
|
|
40
|
+
draftIds.forEach( ( id ) => invalidateComponentDocumentData( id ) );
|
|
41
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type V1ElementData } from '@elementor/editor-elements';
|
|
1
2
|
import type { StyleDefinition } from '@elementor/editor-styles';
|
|
2
3
|
|
|
3
4
|
export type ComponentFormValues = {
|
|
@@ -13,8 +14,17 @@ export type Component = {
|
|
|
13
14
|
name: string;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
export type DocumentStatus = 'publish' | 'draft'
|
|
17
|
+
export type DocumentStatus = 'publish' | 'draft';
|
|
18
|
+
export type DocumentSaveStatus = DocumentStatus | 'autosave';
|
|
17
19
|
|
|
18
20
|
export type ExtendedWindow = Window & {
|
|
19
21
|
elementorCommon: Record< string, unknown >;
|
|
20
22
|
};
|
|
23
|
+
|
|
24
|
+
export type Container = {
|
|
25
|
+
model: {
|
|
26
|
+
get: ( key: 'elements' ) => {
|
|
27
|
+
toJSON: () => V1ElementData[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
+
|
|
3
|
+
import { type DocumentStatus } from '../types';
|
|
4
|
+
|
|
5
|
+
type ComponentDocumentData = {
|
|
6
|
+
id: number;
|
|
7
|
+
elements?: V1ElementData[];
|
|
8
|
+
status: { value: DocumentStatus };
|
|
9
|
+
revisions: { current_id: number };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type ComponentIdTransformerWindow = Window & {
|
|
13
|
+
elementor?: {
|
|
14
|
+
documents?: {
|
|
15
|
+
request: ( id: number ) => Promise< ComponentDocumentData >;
|
|
16
|
+
invalidateCache: ( id: number ) => void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getComponentDocumentData = async ( id: number ) => {
|
|
22
|
+
const documentManager = getDocumentsManager();
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return await documentManager.request( id );
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const invalidateComponentDocumentData = ( id: number ) => {
|
|
32
|
+
const documentManager = getDocumentsManager();
|
|
33
|
+
|
|
34
|
+
documentManager.invalidateCache( id );
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function getDocumentsManager() {
|
|
38
|
+
const extendedWindow = window as unknown as ComponentIdTransformerWindow;
|
|
39
|
+
|
|
40
|
+
const documentManager = extendedWindow.elementor?.documents;
|
|
41
|
+
|
|
42
|
+
if ( ! documentManager ) {
|
|
43
|
+
throw new Error( 'Elementor documents manager not found' );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return documentManager;
|
|
47
|
+
}
|
|
@@ -2,7 +2,7 @@ import { type V1ElementData } from '@elementor/editor-elements';
|
|
|
2
2
|
import { isTransformable } from '@elementor/editor-props';
|
|
3
3
|
|
|
4
4
|
export const getComponentIds = ( elements: V1ElementData[] ) => {
|
|
5
|
-
|
|
5
|
+
const result = elements.flatMap( ( element ) => {
|
|
6
6
|
const ids: number[] = [];
|
|
7
7
|
|
|
8
8
|
const type = element.widgetType || element.elType;
|
|
@@ -17,4 +17,6 @@ export const getComponentIds = ( elements: V1ElementData[] ) => {
|
|
|
17
17
|
|
|
18
18
|
return ids;
|
|
19
19
|
} );
|
|
20
|
+
|
|
21
|
+
return Array.from( new Set( result ) );
|
|
20
22
|
};
|