@elementor/editor-components 3.33.0-289 → 3.33.0-291
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 +31 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/{component-id-transformer.ts → component-instance-transformer.ts} +2 -3
- package/src/components/create-component-form/utils/replace-element-with-component.ts +5 -3
- package/src/create-component-type.ts +17 -11
- package/src/init.ts +2 -2
- package/src/sync/create-components-before-save.ts +12 -7
- package/src/types.ts +15 -0
- package/src/utils/component-document-data.ts +2 -2
- package/src/utils/get-component-ids.ts +9 -3
|
@@ -19,9 +19,11 @@ export const createComponentModel = ( component: ComponentInstanceParams ): Omit
|
|
|
19
19
|
elType: 'widget',
|
|
20
20
|
widgetType: 'e-component',
|
|
21
21
|
settings: {
|
|
22
|
-
|
|
23
|
-
$$type: 'component-
|
|
24
|
-
value:
|
|
22
|
+
component_instance: {
|
|
23
|
+
$$type: 'component-instance',
|
|
24
|
+
value: {
|
|
25
|
+
component_id: component.id ?? component.uid,
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
28
|
},
|
|
27
29
|
editor_settings: {
|
|
@@ -8,12 +8,11 @@ import {
|
|
|
8
8
|
type LegacyWindow,
|
|
9
9
|
} from '@elementor/editor-canvas';
|
|
10
10
|
import { getCurrentDocument } from '@elementor/editor-documents';
|
|
11
|
-
import { type NumberPropValue } from '@elementor/editor-props';
|
|
12
11
|
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
13
12
|
import { __ } from '@wordpress/i18n';
|
|
14
13
|
|
|
15
14
|
import { apiClient } from './api';
|
|
16
|
-
import { type ExtendedWindow } from './types';
|
|
15
|
+
import { type ComponentInstancePropValue, type ExtendedWindow } from './types';
|
|
17
16
|
import { trackComponentEvent } from './utils/tracking';
|
|
18
17
|
|
|
19
18
|
type ContextMenuEventData = { location: string; secondaryLocation: string; trigger: string };
|
|
@@ -46,16 +45,18 @@ function createComponentView(
|
|
|
46
45
|
isComponentCurrentlyEdited() {
|
|
47
46
|
const currentDocument = getCurrentDocument();
|
|
48
47
|
|
|
49
|
-
return currentDocument?.id === this.getComponentId()
|
|
48
|
+
return currentDocument?.id === this.getComponentId();
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
afterSettingsResolve( settings: { [ key: string ]: unknown } ) {
|
|
53
|
-
if ( settings.
|
|
54
|
-
this.collection = this.legacyWindow.elementor.createBackboneElementsCollection(
|
|
52
|
+
if ( settings.component_instance ) {
|
|
53
|
+
this.collection = this.legacyWindow.elementor.createBackboneElementsCollection(
|
|
54
|
+
settings.component_instance
|
|
55
|
+
);
|
|
55
56
|
|
|
56
57
|
this.collection.models.forEach( setInactiveRecursively );
|
|
57
58
|
|
|
58
|
-
settings.
|
|
59
|
+
settings.component_instance = '<template data-children-placeholder></template>';
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
return settings;
|
|
@@ -79,12 +80,16 @@ function createComponentView(
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
getComponentId() {
|
|
82
|
-
|
|
83
|
+
const componentInstance = (
|
|
84
|
+
this.options?.model?.get( 'settings' )?.get( 'component_instance' ) as ComponentInstancePropValue
|
|
85
|
+
)?.value;
|
|
86
|
+
|
|
87
|
+
return componentInstance.component_id;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
getContextMenuGroups() {
|
|
86
91
|
const filteredGroups = super.getContextMenuGroups().filter( ( group ) => group.name !== 'save' );
|
|
87
|
-
const componentId = this.getComponentId()
|
|
92
|
+
const componentId = this.getComponentId();
|
|
88
93
|
if ( ! componentId ) {
|
|
89
94
|
return filteredGroups;
|
|
90
95
|
}
|
|
@@ -108,15 +113,16 @@ function createComponentView(
|
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
async switchDocument() {
|
|
116
|
+
//todo: handle unpublished
|
|
111
117
|
const { isAllowedToSwitchDocument, lockedBy } = await apiClient.getComponentLockStatus(
|
|
112
|
-
this.getComponentId()
|
|
118
|
+
this.getComponentId() as number
|
|
113
119
|
);
|
|
114
120
|
|
|
115
121
|
if ( ! isAllowedToSwitchDocument ) {
|
|
116
122
|
options.showLockedByModal?.( lockedBy || '' );
|
|
117
123
|
} else {
|
|
118
124
|
runCommand( 'editor/documents/switch', {
|
|
119
|
-
id: this.getComponentId()
|
|
125
|
+
id: this.getComponentId(),
|
|
120
126
|
mode: 'autosave',
|
|
121
127
|
selector: `[data-id="${ this.model.get( 'id' ) }"]`,
|
|
122
128
|
shouldScroll: false,
|
|
@@ -165,7 +171,7 @@ function createComponentView(
|
|
|
165
171
|
attributes() {
|
|
166
172
|
return {
|
|
167
173
|
...super.attributes(),
|
|
168
|
-
'data-elementor-id': this.getComponentId()
|
|
174
|
+
'data-elementor-id': this.getComponentId(),
|
|
169
175
|
};
|
|
170
176
|
}
|
|
171
177
|
};
|
package/src/init.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { __privateListenTo as listenTo, commandStartEvent, registerDataHook } fr
|
|
|
12
12
|
import { __registerSlice as registerSlice } from '@elementor/store';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { componentInstanceTransformer } from './component-instance-transformer';
|
|
16
16
|
import { Components } from './components/components-tab/components';
|
|
17
17
|
import { CreateComponentForm } from './components/create-component-form/create-component-form';
|
|
18
18
|
import { EditComponent } from './components/edit-component/edit-component';
|
|
@@ -81,5 +81,5 @@ export function init() {
|
|
|
81
81
|
loadComponentsStyles( ( config?.elements as V1ElementData[] ) ?? [] );
|
|
82
82
|
} );
|
|
83
83
|
|
|
84
|
-
settingsTransformersRegistry.register( 'component-
|
|
84
|
+
settingsTransformersRegistry.register( 'component-instance', componentInstanceTransformer );
|
|
85
85
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { updateElementSettings, type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
-
import { type TransformablePropValue } from '@elementor/editor-props';
|
|
3
2
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
4
3
|
|
|
5
4
|
import { apiClient } from '../api';
|
|
6
5
|
import { selectUnpublishedComponents, slice } from '../store/store';
|
|
7
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type ComponentInstancePropValue,
|
|
8
|
+
type Container,
|
|
9
|
+
type DocumentSaveStatus,
|
|
10
|
+
type UnpublishedComponent,
|
|
11
|
+
} from '../types';
|
|
8
12
|
|
|
9
13
|
export async function createComponentsBeforeSave( {
|
|
10
14
|
container,
|
|
@@ -80,8 +84,9 @@ function shouldUpdateElement(
|
|
|
80
84
|
uidToComponentId: Map< string, number >
|
|
81
85
|
): { shouldUpdate: true; newComponentId: number } | { shouldUpdate: false; newComponentId: null } {
|
|
82
86
|
if ( element.widgetType === 'e-component' ) {
|
|
83
|
-
const currentComponentId = ( element.settings?.
|
|
84
|
-
?.value;
|
|
87
|
+
const currentComponentId = ( element.settings?.component_instance as ComponentInstancePropValue< string > )
|
|
88
|
+
?.value?.component_id;
|
|
89
|
+
|
|
85
90
|
if ( currentComponentId && uidToComponentId.has( currentComponentId ) ) {
|
|
86
91
|
return { shouldUpdate: true, newComponentId: uidToComponentId.get( currentComponentId ) as number };
|
|
87
92
|
}
|
|
@@ -93,9 +98,9 @@ function updateElementComponentId( elementId: string, componentId: number ): voi
|
|
|
93
98
|
updateElementSettings( {
|
|
94
99
|
id: elementId,
|
|
95
100
|
props: {
|
|
96
|
-
|
|
97
|
-
$$type: 'component-
|
|
98
|
-
value: componentId,
|
|
101
|
+
component_instance: {
|
|
102
|
+
$$type: 'component-instance',
|
|
103
|
+
value: { component_id: componentId },
|
|
99
104
|
},
|
|
100
105
|
},
|
|
101
106
|
withHistory: false,
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
+
import { type TransformablePropValue } from '@elementor/editor-props';
|
|
2
3
|
import type { StyleDefinition } from '@elementor/editor-styles';
|
|
3
4
|
|
|
4
5
|
export type ComponentFormValues = {
|
|
@@ -46,3 +47,17 @@ export type Container = {
|
|
|
46
47
|
};
|
|
47
48
|
};
|
|
48
49
|
};
|
|
50
|
+
|
|
51
|
+
export type ComponentInstancePropValue< TComponentId extends number | string = number | string > =
|
|
52
|
+
TransformablePropValue<
|
|
53
|
+
'component-instance',
|
|
54
|
+
{
|
|
55
|
+
component_id: TComponentId;
|
|
56
|
+
overrides?: ComponentOverride[];
|
|
57
|
+
}
|
|
58
|
+
>;
|
|
59
|
+
|
|
60
|
+
type ComponentOverride = {
|
|
61
|
+
override_key: string;
|
|
62
|
+
value: TransformablePropValue< string >;
|
|
63
|
+
};
|
|
@@ -9,7 +9,7 @@ type ComponentDocumentData = {
|
|
|
9
9
|
revisions: { current_id: number };
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
type ComponentInstanceTransformerWindow = Window & {
|
|
13
13
|
elementor?: {
|
|
14
14
|
documents?: {
|
|
15
15
|
request: ( id: number ) => Promise< ComponentDocumentData >;
|
|
@@ -35,7 +35,7 @@ export const invalidateComponentDocumentData = ( id: number ) => {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
function getDocumentsManager() {
|
|
38
|
-
const extendedWindow = window as unknown as
|
|
38
|
+
const extendedWindow = window as unknown as ComponentInstanceTransformerWindow;
|
|
39
39
|
|
|
40
40
|
const documentManager = extendedWindow.elementor?.documents;
|
|
41
41
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { type ComponentInstancePropValue } from '../types';
|
|
3
4
|
|
|
4
5
|
export const getComponentIds = ( elements: V1ElementData[] ) => {
|
|
5
6
|
const result = elements.flatMap( ( element ) => {
|
|
@@ -7,8 +8,13 @@ export const getComponentIds = ( elements: V1ElementData[] ) => {
|
|
|
7
8
|
|
|
8
9
|
const type = element.widgetType || element.elType;
|
|
9
10
|
|
|
10
|
-
if ( type === 'e-component'
|
|
11
|
-
|
|
11
|
+
if ( type === 'e-component' ) {
|
|
12
|
+
const componentId = ( element.settings?.component_instance as ComponentInstancePropValue< number > )?.value
|
|
13
|
+
?.component_id;
|
|
14
|
+
|
|
15
|
+
if ( Boolean( componentId ) ) {
|
|
16
|
+
ids.push( componentId );
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
if ( element.elements ) {
|