@elementor/editor-components 4.0.0-manual → 4.0.0
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 +1422 -1
- package/dist/index.d.ts +1422 -1
- package/dist/index.js +2096 -4814
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2028 -4837
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -23
- package/src/components/components-tab/components-list.tsx +92 -4
- package/src/components/components-tab/components-pro-notification.tsx +9 -15
- package/src/components/components-tab/components-update-notification.tsx +13 -0
- package/src/components/components-tab/components.tsx +52 -3
- package/src/components/components-tab/loading-components.tsx +26 -14
- package/src/components/components-update-alert.tsx +40 -0
- package/src/components/components-upgrade-alert.tsx +39 -0
- package/src/components/detach-instance-confirmation-dialog.tsx +50 -0
- package/src/components/instance-editing-panel/detach-action.tsx +76 -0
- package/src/components/instance-editing-panel/empty-state.tsx +9 -2
- package/src/components/instance-editing-panel/instance-editing-panel.tsx +34 -6
- package/src/components/instance-editing-panel/override-prop-control.tsx +14 -6
- package/src/components/instance-editing-panel/use-instance-panel-data.ts +2 -2
- package/src/components/instance-editing-panel/utils/correct-exposed-empty-override.ts +28 -0
- package/src/consts.ts +1 -0
- package/src/create-component-type.ts +130 -29
- package/src/index.ts +92 -0
- package/src/init.ts +6 -4
- package/src/store/actions/update-overridable-prop.ts +4 -10
- package/src/store/dispatchers.ts +63 -0
- package/src/store/extensible-slice.ts +168 -0
- package/src/store/selectors.ts +53 -0
- package/src/store/store-types.ts +48 -0
- package/src/store/store.ts +7 -169
- package/src/sync/publish-draft-components-in-page-before-save.ts +42 -1
- package/src/types.ts +1 -1
- package/src/utils/detach-component-instance/detach-component-instance.ts +172 -0
- package/src/utils/detach-component-instance/index.ts +1 -0
- package/src/utils/detach-component-instance/regenerate-local-style-ids.ts +53 -0
- package/src/utils/detach-component-instance/resolve-detached-instance.ts +94 -0
- package/src/utils/detach-component-instance/resolve-overridable-settings.ts +121 -0
- package/src/utils/is-component-instance.ts +1 -1
- package/src/utils/is-pro-components-supported.ts +11 -0
- package/src/utils/tracking.ts +2 -1
- package/src/extended/components/component-introduction.tsx +0 -77
- package/src/extended/components/component-panel-header/component-badge.tsx +0 -73
- package/src/extended/components/component-panel-header/component-panel-header.tsx +0 -98
- package/src/extended/components/component-properties-panel/component-properties-panel-content.tsx +0 -176
- package/src/extended/components/component-properties-panel/component-properties-panel.tsx +0 -43
- package/src/extended/components/component-properties-panel/properties-empty-state.tsx +0 -51
- package/src/extended/components/component-properties-panel/properties-group.tsx +0 -196
- package/src/extended/components/component-properties-panel/property-item.tsx +0 -124
- package/src/extended/components/component-properties-panel/sortable.tsx +0 -92
- package/src/extended/components/component-properties-panel/use-current-editable-item.ts +0 -73
- package/src/extended/components/component-properties-panel/utils/generate-unique-label.ts +0 -21
- package/src/extended/components/component-properties-panel/utils/validate-group-label.ts +0 -24
- package/src/extended/components/components-tab/component-item.tsx +0 -180
- package/src/extended/components/components-tab/components.tsx +0 -58
- package/src/extended/components/components-tab/delete-confirmation-dialog.tsx +0 -26
- package/src/extended/components/create-component-form/create-component-form.tsx +0 -282
- package/src/extended/components/create-component-form/hooks/use-form.ts +0 -72
- package/src/extended/components/create-component-form/utils/get-component-event-data.ts +0 -54
- package/src/extended/components/edit-component/component-modal.tsx +0 -133
- package/src/extended/components/edit-component/edit-component.tsx +0 -166
- package/src/extended/components/edit-component/use-canvas-document.ts +0 -9
- package/src/extended/components/edit-component/use-element-rect.ts +0 -81
- package/src/extended/components/instance-editing-panel/instance-editing-panel.tsx +0 -60
- package/src/extended/components/overridable-props/indicator.tsx +0 -83
- package/src/extended/components/overridable-props/overridable-prop-control.tsx +0 -127
- package/src/extended/components/overridable-props/overridable-prop-form.tsx +0 -135
- package/src/extended/components/overridable-props/overridable-prop-indicator.tsx +0 -138
- package/src/extended/components/overridable-props/utils/validate-prop-label.ts +0 -38
- package/src/extended/consts.ts +0 -3
- package/src/extended/hooks/use-navigate-back.ts +0 -24
- package/src/extended/init.ts +0 -104
- package/src/extended/mcp/index.ts +0 -14
- package/src/extended/mcp/save-as-component-tool.ts +0 -436
- package/src/extended/store/actions/add-overridable-group.ts +0 -59
- package/src/extended/store/actions/archive-component.ts +0 -19
- package/src/extended/store/actions/create-unpublished-component.ts +0 -102
- package/src/extended/store/actions/delete-overridable-group.ts +0 -38
- package/src/extended/store/actions/delete-overridable-prop.ts +0 -70
- package/src/extended/store/actions/rename-component.ts +0 -49
- package/src/extended/store/actions/rename-overridable-group.ts +0 -39
- package/src/extended/store/actions/reorder-group-props.ts +0 -43
- package/src/extended/store/actions/reorder-overridable-groups.ts +0 -30
- package/src/extended/store/actions/reset-sanitized-components.ts +0 -7
- package/src/extended/store/actions/set-overridable-prop.ts +0 -117
- package/src/extended/store/actions/update-component-sanitized-attribute.ts +0 -8
- package/src/extended/store/actions/update-current-component.ts +0 -21
- package/src/extended/store/actions/update-overridable-prop-params.ts +0 -58
- package/src/extended/store/utils/groups-transformers.ts +0 -187
- package/src/extended/sync/before-save.ts +0 -52
- package/src/extended/sync/cleanup-overridable-props-on-delete.ts +0 -85
- package/src/extended/sync/create-components-before-save.ts +0 -113
- package/src/extended/sync/handle-component-edit-mode-container.ts +0 -114
- package/src/extended/sync/prevent-non-atomic-nesting.ts +0 -198
- package/src/extended/sync/revert-overridables-on-copy-or-duplicate.ts +0 -66
- package/src/extended/sync/sanitize-overridable-props.ts +0 -32
- package/src/extended/sync/set-component-overridable-props-settings-before-save.ts +0 -23
- package/src/extended/sync/update-archived-component-before-save.ts +0 -32
- package/src/extended/sync/update-component-title-before-save.ts +0 -19
- package/src/extended/utils/component-form-schema.ts +0 -32
- package/src/extended/utils/component-name-validation.ts +0 -27
- package/src/extended/utils/create-component-model.ts +0 -28
- package/src/extended/utils/get-container-for-new-element.ts +0 -49
- package/src/extended/utils/is-editing-component.ts +0 -13
- package/src/extended/utils/replace-element-with-component.ts +0 -11
- package/src/extended/utils/revert-overridable-settings.ts +0 -207
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { z } from '@elementor/schema';
|
|
2
|
-
import { __ } from '@wordpress/i18n';
|
|
3
|
-
|
|
4
|
-
export const MIN_NAME_LENGTH = 2;
|
|
5
|
-
const MAX_NAME_LENGTH = 50;
|
|
6
|
-
|
|
7
|
-
const baseComponentSchema = z
|
|
8
|
-
.string()
|
|
9
|
-
.trim()
|
|
10
|
-
.max( MAX_NAME_LENGTH, __( 'Component name is too long. Please keep it under 50 characters.', 'elementor' ) );
|
|
11
|
-
|
|
12
|
-
export const createBaseComponentSchema = ( existingNames: string[] ) => {
|
|
13
|
-
return z.object( {
|
|
14
|
-
componentName: baseComponentSchema.refine( ( value ) => ! existingNames.includes( value ), {
|
|
15
|
-
message: __( 'Component name already exists', 'elementor' ),
|
|
16
|
-
} ),
|
|
17
|
-
} );
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const createSubmitComponentSchema = ( existingNames: string[] ) => {
|
|
21
|
-
const baseSchema = createBaseComponentSchema( existingNames );
|
|
22
|
-
|
|
23
|
-
return baseSchema.extend( {
|
|
24
|
-
componentName: baseSchema.shape.componentName
|
|
25
|
-
.refine( ( value ) => value.length > 0, {
|
|
26
|
-
message: __( 'Component name is required.', 'elementor' ),
|
|
27
|
-
} )
|
|
28
|
-
.refine( ( value ) => value.length >= MIN_NAME_LENGTH, {
|
|
29
|
-
message: __( 'Component name is too short. Please enter at least 2 characters.', 'elementor' ),
|
|
30
|
-
} ),
|
|
31
|
-
} );
|
|
32
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { __getState as getState } from '@elementor/store';
|
|
2
|
-
|
|
3
|
-
import { selectComponents } from '../../store/store';
|
|
4
|
-
import { createSubmitComponentSchema } from './component-form-schema';
|
|
5
|
-
|
|
6
|
-
type ValidationResult = { isValid: true; errorMessage: null } | { isValid: false; errorMessage: string };
|
|
7
|
-
|
|
8
|
-
export function validateComponentName( label: string ): ValidationResult {
|
|
9
|
-
const existingComponentTitles = selectComponents( getState() )?.map( ( { name } ) => name ) ?? [];
|
|
10
|
-
const schema = createSubmitComponentSchema( existingComponentTitles );
|
|
11
|
-
const result = schema.safeParse( { componentName: label.toLowerCase() } );
|
|
12
|
-
|
|
13
|
-
if ( result.success ) {
|
|
14
|
-
return {
|
|
15
|
-
isValid: true,
|
|
16
|
-
errorMessage: null,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const formattedErrors = result.error.format();
|
|
21
|
-
const errorMessage = formattedErrors.componentName?._errors[ 0 ] ?? formattedErrors._errors[ 0 ];
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
isValid: false,
|
|
25
|
-
errorMessage,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type V1ElementModelProps } from '@elementor/editor-elements';
|
|
2
|
-
|
|
3
|
-
export type ComponentInstanceParams = {
|
|
4
|
-
id?: number;
|
|
5
|
-
name: string;
|
|
6
|
-
uid: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const createComponentModel = ( component: ComponentInstanceParams ): Omit< V1ElementModelProps, 'id' > => {
|
|
10
|
-
return {
|
|
11
|
-
elType: 'widget',
|
|
12
|
-
widgetType: 'e-component',
|
|
13
|
-
settings: {
|
|
14
|
-
component_instance: {
|
|
15
|
-
$$type: 'component-instance',
|
|
16
|
-
value: {
|
|
17
|
-
component_id: {
|
|
18
|
-
$$type: 'number',
|
|
19
|
-
value: component.id ?? component.uid,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
editor_settings: {
|
|
25
|
-
component_uid: component.uid,
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getContainer,
|
|
3
|
-
getCurrentDocumentContainer,
|
|
4
|
-
getSelectedElements,
|
|
5
|
-
type V1Element,
|
|
6
|
-
} from '@elementor/editor-elements';
|
|
7
|
-
|
|
8
|
-
export const getContainerForNewElement = (): { container: V1Element | null; options?: { at: number } } => {
|
|
9
|
-
const currentDocumentContainer = getCurrentDocumentContainer();
|
|
10
|
-
const selectedElement = getSelectedElementContainer();
|
|
11
|
-
|
|
12
|
-
let container, options;
|
|
13
|
-
|
|
14
|
-
if ( selectedElement ) {
|
|
15
|
-
switch ( selectedElement.model.get( 'elType' ) ) {
|
|
16
|
-
case 'widget': {
|
|
17
|
-
container = selectedElement?.parent;
|
|
18
|
-
|
|
19
|
-
const selectedElIndex = selectedElement.view?._index ?? -1;
|
|
20
|
-
|
|
21
|
-
if ( selectedElIndex > -1 ) {
|
|
22
|
-
options = { at: selectedElIndex + 1 };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
case 'section': {
|
|
28
|
-
container = selectedElement?.children?.[ 0 ];
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
default: {
|
|
32
|
-
container = selectedElement;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { container: container ?? currentDocumentContainer, options };
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
function getSelectedElementContainer() {
|
|
42
|
-
const selectedElements = getSelectedElements();
|
|
43
|
-
|
|
44
|
-
if ( selectedElements.length !== 1 ) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return getContainer( selectedElements[ 0 ].id );
|
|
49
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { __getStore as getStore } from '@elementor/store';
|
|
2
|
-
|
|
3
|
-
import { type ComponentsSlice, selectCurrentComponentId } from '../../store/store';
|
|
4
|
-
|
|
5
|
-
export function isEditingComponent(): boolean {
|
|
6
|
-
const state = getStore()?.getState() as ComponentsSlice | undefined;
|
|
7
|
-
|
|
8
|
-
if ( ! state ) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return selectCurrentComponentId( state ) !== null;
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { replaceElement, type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
-
|
|
3
|
-
import { type ComponentInstanceParams, createComponentModel } from './create-component-model';
|
|
4
|
-
|
|
5
|
-
export const replaceElementWithComponent = async ( element: V1ElementData, component: ComponentInstanceParams ) => {
|
|
6
|
-
return await replaceElement( {
|
|
7
|
-
currentElement: element,
|
|
8
|
-
newElement: createComponentModel( component ),
|
|
9
|
-
withHistory: false,
|
|
10
|
-
} );
|
|
11
|
-
};
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAllDescendants,
|
|
3
|
-
getContainer,
|
|
4
|
-
getElementSetting,
|
|
5
|
-
updateElementSettings,
|
|
6
|
-
type V1Element,
|
|
7
|
-
type V1ElementData,
|
|
8
|
-
type V1ElementSettingsProps,
|
|
9
|
-
} from '@elementor/editor-elements';
|
|
10
|
-
|
|
11
|
-
import { COMPONENT_WIDGET_TYPE } from '../../create-component-type';
|
|
12
|
-
import {
|
|
13
|
-
type ComponentInstanceOverrideProp,
|
|
14
|
-
componentInstanceOverridePropTypeUtil,
|
|
15
|
-
} from '../../prop-types/component-instance-override-prop-type';
|
|
16
|
-
import {
|
|
17
|
-
componentInstanceOverridesPropTypeUtil,
|
|
18
|
-
type ComponentInstanceOverridesPropValue,
|
|
19
|
-
} from '../../prop-types/component-instance-overrides-prop-type';
|
|
20
|
-
import {
|
|
21
|
-
type ComponentInstanceProp,
|
|
22
|
-
componentInstancePropTypeUtil,
|
|
23
|
-
type ComponentInstancePropValue,
|
|
24
|
-
} from '../../prop-types/component-instance-prop-type';
|
|
25
|
-
import { componentOverridablePropTypeUtil } from '../../prop-types/component-overridable-prop-type';
|
|
26
|
-
import { isComponentInstance } from '../../utils/is-component-instance';
|
|
27
|
-
|
|
28
|
-
type RevertSettingsResult = {
|
|
29
|
-
hasChanges: boolean;
|
|
30
|
-
settings: V1ElementSettingsProps;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function revertElementOverridableSetting(
|
|
34
|
-
elementId: string,
|
|
35
|
-
settingKey: string,
|
|
36
|
-
originValue: unknown,
|
|
37
|
-
overrideKey: string
|
|
38
|
-
): void {
|
|
39
|
-
const container = getContainer( elementId );
|
|
40
|
-
|
|
41
|
-
if ( ! container ) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ( isComponentInstance( container.model.toJSON() ) ) {
|
|
46
|
-
revertComponentInstanceOverridableSetting( elementId, overrideKey );
|
|
47
|
-
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
updateElementSettings( {
|
|
52
|
-
id: elementId,
|
|
53
|
-
props: { [ settingKey ]: originValue ?? null },
|
|
54
|
-
withHistory: false,
|
|
55
|
-
} );
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function revertComponentInstanceOverridableSetting( elementId: string, overrideKey: string ): void {
|
|
59
|
-
const setting = getElementSetting< ComponentInstanceProp >( elementId, 'component_instance' );
|
|
60
|
-
|
|
61
|
-
const componentInstance = componentInstancePropTypeUtil.extract( setting );
|
|
62
|
-
const overrides = componentInstanceOverridesPropTypeUtil.extract( componentInstance?.overrides );
|
|
63
|
-
|
|
64
|
-
if ( ! overrides?.length ) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const revertedOverrides = revertComponentInstanceOverrides( overrides, overrideKey );
|
|
69
|
-
|
|
70
|
-
const updatedSetting = componentInstancePropTypeUtil.create( {
|
|
71
|
-
...componentInstance,
|
|
72
|
-
overrides: componentInstanceOverridesPropTypeUtil.create( revertedOverrides ),
|
|
73
|
-
} as ComponentInstancePropValue );
|
|
74
|
-
|
|
75
|
-
updateElementSettings( {
|
|
76
|
-
id: elementId,
|
|
77
|
-
props: { component_instance: updatedSetting },
|
|
78
|
-
withHistory: false,
|
|
79
|
-
} );
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function revertComponentInstanceOverrides(
|
|
83
|
-
overrides: NonNullable< ComponentInstanceOverridesPropValue >,
|
|
84
|
-
filterByKey?: string
|
|
85
|
-
): ComponentInstanceOverridesPropValue {
|
|
86
|
-
return overrides
|
|
87
|
-
.map( ( item ) => {
|
|
88
|
-
if ( ! componentOverridablePropTypeUtil.isValid( item ) ) {
|
|
89
|
-
return item;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if ( ! componentInstanceOverridePropTypeUtil.isValid( item.value.origin_value ) ) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if ( filterByKey && item.value.override_key !== filterByKey ) {
|
|
97
|
-
return item;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return item.value.origin_value as ComponentInstanceOverrideProp;
|
|
101
|
-
} )
|
|
102
|
-
.filter( ( item ): item is NonNullable< typeof item > => item !== null );
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function revertOverridablePropsFromSettings( settings: V1ElementSettingsProps ): RevertSettingsResult {
|
|
106
|
-
let hasChanges = false;
|
|
107
|
-
const revertedSettings: V1ElementSettingsProps = {};
|
|
108
|
-
|
|
109
|
-
for ( const [ key, value ] of Object.entries( settings ) ) {
|
|
110
|
-
if ( componentOverridablePropTypeUtil.isValid( value ) ) {
|
|
111
|
-
revertedSettings[ key ] = value.value.origin_value;
|
|
112
|
-
hasChanges = true;
|
|
113
|
-
} else {
|
|
114
|
-
revertedSettings[ key ] = value;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return { hasChanges, settings: revertedSettings };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function revertAllOverridablesInElementData( elementData: V1ElementData ): V1ElementData {
|
|
122
|
-
const revertedElement = { ...elementData };
|
|
123
|
-
|
|
124
|
-
if ( isComponentInstance( { widgetType: elementData.widgetType, elType: elementData.elType } ) ) {
|
|
125
|
-
revertedElement.settings = revertComponentInstanceSettings( elementData.settings );
|
|
126
|
-
} else if ( revertedElement.settings ) {
|
|
127
|
-
const { settings } = revertOverridablePropsFromSettings( revertedElement.settings );
|
|
128
|
-
revertedElement.settings = settings;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if ( revertedElement.elements ) {
|
|
132
|
-
revertedElement.elements = revertedElement.elements.map( revertAllOverridablesInElementData );
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return revertedElement;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function revertComponentInstanceSettings( settings: V1ElementData[ 'settings' ] ): V1ElementData[ 'settings' ] {
|
|
139
|
-
if ( ! settings?.component_instance ) {
|
|
140
|
-
return settings;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const componentInstance = componentInstancePropTypeUtil.extract( settings.component_instance );
|
|
144
|
-
const overrides = componentInstanceOverridesPropTypeUtil.extract( componentInstance?.overrides );
|
|
145
|
-
|
|
146
|
-
if ( ! overrides?.length ) {
|
|
147
|
-
return settings;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const revertedOverrides = revertComponentInstanceOverrides( overrides );
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
...settings,
|
|
154
|
-
component_instance: componentInstancePropTypeUtil.create( {
|
|
155
|
-
...componentInstance,
|
|
156
|
-
overrides: componentInstanceOverridesPropTypeUtil.create( revertedOverrides ),
|
|
157
|
-
} as ComponentInstancePropValue ),
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function revertAllOverridablesInContainer( container: V1Element ): void {
|
|
162
|
-
getAllDescendants( container ).forEach( ( element ) => {
|
|
163
|
-
if ( element.model.get( 'widgetType' ) === COMPONENT_WIDGET_TYPE ) {
|
|
164
|
-
revertComponentInstanceOverridesInElement( element );
|
|
165
|
-
} else {
|
|
166
|
-
revertElementSettings( element );
|
|
167
|
-
}
|
|
168
|
-
} );
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function revertComponentInstanceOverridesInElement( element: V1Element ): void {
|
|
172
|
-
const settings = element.settings?.toJSON() ?? {};
|
|
173
|
-
const componentInstance = componentInstancePropTypeUtil.extract( settings.component_instance );
|
|
174
|
-
const overrides = componentInstanceOverridesPropTypeUtil.extract( componentInstance?.overrides );
|
|
175
|
-
|
|
176
|
-
if ( ! overrides?.length ) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const revertedOverrides = revertComponentInstanceOverrides( overrides );
|
|
181
|
-
|
|
182
|
-
const updatedSetting = componentInstancePropTypeUtil.create( {
|
|
183
|
-
...componentInstance,
|
|
184
|
-
overrides: componentInstanceOverridesPropTypeUtil.create( revertedOverrides ),
|
|
185
|
-
} as ComponentInstancePropValue );
|
|
186
|
-
|
|
187
|
-
updateElementSettings( {
|
|
188
|
-
id: element.id,
|
|
189
|
-
props: { component_instance: updatedSetting },
|
|
190
|
-
withHistory: false,
|
|
191
|
-
} );
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function revertElementSettings( element: V1Element ): void {
|
|
195
|
-
const settings = element.settings?.toJSON() ?? {};
|
|
196
|
-
const { hasChanges, settings: revertedSettings } = revertOverridablePropsFromSettings( settings );
|
|
197
|
-
|
|
198
|
-
if ( ! hasChanges ) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
updateElementSettings( {
|
|
203
|
-
id: element.id,
|
|
204
|
-
props: revertedSettings,
|
|
205
|
-
withHistory: false,
|
|
206
|
-
} );
|
|
207
|
-
}
|