@elementor/editor-components 4.0.0-564 → 4.0.0-591
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 +3801 -3744
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3813 -3761
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -22
- package/src/components/components-tab/components-item.tsx +5 -4
- package/src/components/components-tab/components-list.tsx +5 -13
- package/src/components/components-tab/loading-components.tsx +2 -3
- package/src/components/instance-editing-panel/instance-editing-panel.tsx +17 -5
- package/src/components/instance-editing-panel/override-prop-control.tsx +13 -7
- package/src/components/instance-editing-panel/use-resolved-origin-value.tsx +1 -1
- package/src/components/load-template-components.tsx +14 -0
- package/src/create-component-type.ts +8 -2
- package/src/{components → extended/components}/component-panel-header/component-panel-header.tsx +4 -4
- package/src/{components → extended/components}/component-properties-panel/component-properties-panel-content.tsx +2 -2
- package/src/{components → extended/components}/component-properties-panel/properties-empty-state.tsx +1 -1
- package/src/{components → extended/components}/component-properties-panel/properties-group.tsx +1 -1
- package/src/{components → extended/components}/component-properties-panel/property-item.tsx +1 -1
- package/src/{components → extended/components}/component-properties-panel/use-current-editable-item.ts +1 -1
- package/src/{components → extended/components}/component-properties-panel/utils/generate-unique-label.ts +1 -1
- package/src/{components → extended/components}/component-properties-panel/utils/validate-group-label.ts +1 -1
- package/src/{components → extended/components}/create-component-form/create-component-form.tsx +5 -5
- package/src/{components → extended/components}/edit-component/component-modal.tsx +2 -2
- package/src/{components → extended/components}/edit-component/edit-component.tsx +3 -3
- package/src/{components → extended/components}/overridable-props/overridable-prop-control.tsx +7 -7
- package/src/{components → extended/components}/overridable-props/overridable-prop-form.tsx +1 -1
- package/src/{components → extended/components}/overridable-props/overridable-prop-indicator.tsx +7 -7
- package/src/{components → extended}/consts.ts +2 -1
- package/src/{hooks → extended/hooks}/use-navigate-back.ts +2 -2
- package/src/extended/init.ts +77 -0
- package/src/{mcp → extended/mcp}/save-as-component-tool.ts +2 -2
- package/src/{prevent-non-atomic-nesting.ts → extended/prevent-non-atomic-nesting.ts} +1 -1
- package/src/{store → extended/store}/actions/add-overridable-group.ts +3 -3
- package/src/{store → extended/store}/actions/create-unpublished-component.ts +4 -4
- package/src/{store → extended/store}/actions/delete-overridable-group.ts +2 -2
- package/src/extended/store/actions/delete-overridable-prop.ts +70 -0
- package/src/{store → extended/store}/actions/rename-overridable-group.ts +2 -2
- package/src/{store → extended/store}/actions/reorder-group-props.ts +2 -2
- package/src/{store → extended/store}/actions/reorder-overridable-groups.ts +2 -2
- package/src/{store → extended/store}/actions/reset-sanitized-components.ts +1 -1
- package/src/{store → extended/store}/actions/set-overridable-prop.ts +3 -3
- package/src/{store → extended/store}/actions/update-component-sanitized-attribute.ts +2 -2
- package/src/{store → extended/store}/actions/update-current-component.ts +2 -14
- package/src/{store → extended/store}/actions/update-overridable-prop-params.ts +2 -2
- package/src/{store → extended/store}/utils/groups-transformers.ts +6 -4
- package/src/extended/sync/before-save.ts +52 -0
- package/src/{sync → extended/sync}/cleanup-overridable-props-on-delete.ts +24 -24
- package/src/{sync → extended/sync}/create-components-before-save.ts +4 -4
- package/src/{sync → extended/sync}/handle-component-edit-mode-container.ts +1 -1
- package/src/{sync → extended/sync}/revert-overridables-on-copy-or-duplicate.ts +1 -1
- package/src/{sync → extended/sync}/set-component-overridable-props-settings-before-save.ts +2 -2
- package/src/{sync → extended/sync}/update-archived-component-before-save.ts +3 -3
- package/src/{sync → extended/sync}/update-component-title-before-save.ts +3 -3
- package/src/{utils → extended/utils}/is-editing-component.ts +1 -1
- package/src/extended/utils/replace-element-with-component.ts +11 -0
- package/src/{utils → extended/utils}/revert-overridable-settings.ts +6 -6
- package/src/hooks/use-sanitize-overridable-props.ts +9 -4
- package/src/init.ts +8 -69
- package/src/sync/before-save.ts +1 -30
- package/src/types.ts +8 -1
- package/src/utils/component-name-validation.ts +1 -1
- package/src/{components/create-component-form/utils/replace-element-with-component.ts → utils/create-component-model.ts} +2 -10
- package/src/utils/filter-valid-overridable-props.ts +18 -8
- package/src/utils/format-component-elements-id.ts +20 -0
- package/src/utils/get-container-by-origin-id.ts +46 -0
- package/src/{components/overridable-props/utils → utils}/get-overridable-prop.ts +2 -2
- package/src/utils/switch-to-component.ts +5 -2
- package/src/hooks/use-component-instance-settings.ts +0 -15
- package/src/store/actions/delete-overridable-prop.ts +0 -56
- package/src/utils/expand-navigator.ts +0 -5
- /package/src/{components/components-tab → extended/components}/component-introduction.tsx +0 -0
- /package/src/{components → extended/components}/component-panel-header/component-badge.tsx +0 -0
- /package/src/{components → extended/components}/component-properties-panel/component-properties-panel.tsx +0 -0
- /package/src/{components → extended/components}/component-properties-panel/sortable.tsx +0 -0
- /package/src/{components → extended/components}/create-component-form/hooks/use-form.ts +0 -0
- /package/src/{components → extended/components}/create-component-form/utils/component-form-schema.ts +0 -0
- /package/src/{components → extended/components}/create-component-form/utils/get-component-event-data.ts +0 -0
- /package/src/{hooks → extended/components/edit-component}/use-canvas-document.ts +0 -0
- /package/src/{hooks → extended/components/edit-component}/use-element-rect.ts +0 -0
- /package/src/{components → extended/components}/overridable-props/indicator.tsx +0 -0
- /package/src/{components → extended/components}/overridable-props/utils/validate-prop-label.ts +0 -0
- /package/src/{mcp → extended/mcp}/index.ts +0 -0
|
@@ -4,7 +4,7 @@ import { type NotificationData, notify } from '@elementor/editor-notifications';
|
|
|
4
4
|
import { blockCommand } from '@elementor/editor-v1-adapters';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
|
|
7
|
-
import { type ExtendedWindow } from '
|
|
7
|
+
import { type ExtendedWindow } from '../types';
|
|
8
8
|
import { isEditingComponent } from './utils/is-editing-component';
|
|
9
9
|
|
|
10
10
|
type CreateArgs = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { type
|
|
5
|
-
import {
|
|
3
|
+
import { selectCurrentComponent, selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId, type OverridablePropsGroup } from '../../../types';
|
|
5
|
+
import { type Source, trackComponentEvent } from '../../../utils/tracking';
|
|
6
6
|
|
|
7
7
|
type AddGroupParams = {
|
|
8
8
|
componentId: ComponentId;
|
|
@@ -4,12 +4,12 @@ import { __dispatch as dispatch } from '@elementor/store';
|
|
|
4
4
|
import { generateUniqueId } from '@elementor/utils';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
|
|
7
|
+
import { slice } from '../../../store/store';
|
|
8
|
+
import { type OriginalElementData, type OverridableProps } from '../../../types';
|
|
9
|
+
import { type Source, trackComponentEvent } from '../../../utils/tracking';
|
|
7
10
|
import { type ComponentEventData } from '../../components/create-component-form/utils/get-component-event-data';
|
|
8
|
-
import { replaceElementWithComponent } from '../../
|
|
9
|
-
import { type OriginalElementData, type OverridableProps } from '../../types';
|
|
11
|
+
import { replaceElementWithComponent } from '../../utils/replace-element-with-component';
|
|
10
12
|
import { revertAllOverridablesInElementData } from '../../utils/revert-overridable-settings';
|
|
11
|
-
import { type Source, trackComponentEvent } from '../../utils/tracking';
|
|
12
|
-
import { slice } from '../store';
|
|
13
13
|
|
|
14
14
|
type CreateUnpublishedComponentParams = {
|
|
15
15
|
name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId } from '../../../types';
|
|
5
5
|
import { deleteGroup } from '../utils/groups-transformers';
|
|
6
6
|
|
|
7
7
|
type DeleteGroupParams = {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
|
+
|
|
3
|
+
import { selectCurrentComponent, selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId, type OverridableProp } from '../../../types';
|
|
5
|
+
import { type Source, trackComponentEvent } from '../../../utils/tracking';
|
|
6
|
+
import { revertElementOverridableSetting } from '../../utils/revert-overridable-settings';
|
|
7
|
+
import { removePropFromAllGroups } from '../utils/groups-transformers';
|
|
8
|
+
|
|
9
|
+
type DeletePropParams = {
|
|
10
|
+
componentId: ComponentId;
|
|
11
|
+
propKey: string | string[];
|
|
12
|
+
source: Source;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function deleteOverridableProp( { componentId, propKey, source }: DeletePropParams ): void {
|
|
16
|
+
const overridableProps = selectOverridableProps( getState(), componentId );
|
|
17
|
+
|
|
18
|
+
if ( ! overridableProps || Object.keys( overridableProps.props ).length === 0 ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const propKeysToDelete = Array.isArray( propKey ) ? propKey : [ propKey ];
|
|
23
|
+
const deletedProps: OverridableProp[] = [];
|
|
24
|
+
|
|
25
|
+
for ( const key of propKeysToDelete ) {
|
|
26
|
+
const prop = overridableProps.props[ key ];
|
|
27
|
+
|
|
28
|
+
if ( ! prop ) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
deletedProps.push( prop );
|
|
33
|
+
revertElementOverridableSetting( prop.elementId, prop.propKey, prop.originValue, key );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if ( deletedProps.length === 0 ) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const remainingProps = Object.fromEntries(
|
|
41
|
+
Object.entries( overridableProps.props ).filter( ( [ key ] ) => ! propKeysToDelete.includes( key ) )
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const updatedGroups = removePropFromAllGroups( overridableProps.groups, propKey );
|
|
45
|
+
|
|
46
|
+
dispatch(
|
|
47
|
+
slice.actions.setOverridableProps( {
|
|
48
|
+
componentId,
|
|
49
|
+
overridableProps: {
|
|
50
|
+
...overridableProps,
|
|
51
|
+
props: remainingProps,
|
|
52
|
+
groups: updatedGroups,
|
|
53
|
+
},
|
|
54
|
+
} )
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const currentComponent = selectCurrentComponent( getState() );
|
|
58
|
+
|
|
59
|
+
for ( const prop of deletedProps ) {
|
|
60
|
+
trackComponentEvent( {
|
|
61
|
+
action: 'propertyRemoved',
|
|
62
|
+
source,
|
|
63
|
+
component_uid: currentComponent?.uid,
|
|
64
|
+
property_id: prop.overrideKey,
|
|
65
|
+
property_path: prop.propKey,
|
|
66
|
+
property_name: prop.label,
|
|
67
|
+
element_type: prop.widgetType ?? prop.elType,
|
|
68
|
+
} );
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId } from '../../../types';
|
|
5
5
|
import { renameGroup } from '../utils/groups-transformers';
|
|
6
6
|
|
|
7
7
|
type RenameGroupParams = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId } from '../../../types';
|
|
5
5
|
|
|
6
6
|
type ReorderGroupPropsParams = {
|
|
7
7
|
componentId: ComponentId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId } from '../../../types';
|
|
5
5
|
|
|
6
6
|
type ReorderGroupsParams = {
|
|
7
7
|
componentId: ComponentId;
|
|
@@ -2,9 +2,9 @@ import { type PropValue } from '@elementor/editor-props';
|
|
|
2
2
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
3
3
|
import { generateUniqueId } from '@elementor/utils';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { type
|
|
7
|
-
import {
|
|
5
|
+
import { selectCurrentComponent, selectOverridableProps, slice } from '../../../store/store';
|
|
6
|
+
import { type OriginPropFields, type OverridableProp } from '../../../types';
|
|
7
|
+
import { type Source, trackComponentEvent } from '../../../utils/tracking';
|
|
8
8
|
import {
|
|
9
9
|
addPropToGroup,
|
|
10
10
|
ensureGroupInOrder,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import { type
|
|
4
|
-
import { type
|
|
3
|
+
import { type SanitizeAttributes, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId } from '../../../types';
|
|
5
5
|
|
|
6
6
|
export function updateComponentSanitizedAttribute( componentId: ComponentId, attribute: SanitizeAttributes ) {
|
|
7
7
|
dispatch( slice.actions.updateComponentSanitizedAttribute( { componentId, attribute } ) );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type V1Document } from '@elementor/editor-documents';
|
|
2
2
|
import { __getStore as getStore } from '@elementor/store';
|
|
3
3
|
|
|
4
|
-
import { type ComponentsPathItem, slice } from '
|
|
4
|
+
import { type ComponentsPathItem, slice } from '../../../store/store';
|
|
5
5
|
|
|
6
6
|
export function updateCurrentComponent( {
|
|
7
7
|
path,
|
|
@@ -19,15 +19,3 @@ export function updateCurrentComponent( {
|
|
|
19
19
|
dispatch( slice.actions.setPath( path ) );
|
|
20
20
|
dispatch( slice.actions.setCurrentComponentId( currentComponentId ) );
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
export const archiveComponent = ( componentId: number ) => {
|
|
24
|
-
const store = getStore();
|
|
25
|
-
const dispatch = store?.dispatch;
|
|
26
|
-
|
|
27
|
-
if ( ! dispatch ) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
dispatch( slice.actions.archive( componentId ) );
|
|
32
|
-
setDocumentModifiedStatus( true );
|
|
33
|
-
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { selectOverridableProps, slice } from '../../../store/store';
|
|
4
|
+
import { type ComponentId, type OverridableProp } from '../../../types';
|
|
5
5
|
import { movePropBetweenGroups } from '../utils/groups-transformers';
|
|
6
6
|
|
|
7
7
|
type UpdatePropParams = {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { generateUniqueId } from '@elementor/utils';
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
3
|
|
|
4
|
-
import { type OverridableProp, type OverridableProps, type OverridablePropsGroup } from '
|
|
4
|
+
import { type OverridableProp, type OverridableProps, type OverridablePropsGroup } from '../../../types';
|
|
5
5
|
|
|
6
6
|
type Groups = OverridableProps[ 'groups' ];
|
|
7
7
|
|
|
8
|
-
export function removePropFromAllGroups( groups: Groups, propKey: string ): Groups {
|
|
8
|
+
export function removePropFromAllGroups( groups: Groups, propKey: string | string[] ): Groups {
|
|
9
|
+
const propKeys = Array.isArray( propKey ) ? propKey : [ propKey ];
|
|
10
|
+
|
|
9
11
|
return {
|
|
10
12
|
...groups,
|
|
11
13
|
items: Object.fromEntries(
|
|
@@ -13,7 +15,7 @@ export function removePropFromAllGroups( groups: Groups, propKey: string ): Grou
|
|
|
13
15
|
groupId,
|
|
14
16
|
{
|
|
15
17
|
...group,
|
|
16
|
-
props: group.props.filter( ( p ) =>
|
|
18
|
+
props: group.props.filter( ( p ) => ! propKeys.includes( p ) ),
|
|
17
19
|
},
|
|
18
20
|
] )
|
|
19
21
|
),
|
|
@@ -93,7 +95,7 @@ export function resolveOrCreateGroup( groups: Groups, requestedGroupId?: string
|
|
|
93
95
|
return createGroup( groups, requestedGroupId );
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
function createGroup( groups: Groups, groupId?: string, label?: string ): ResolvedGroup {
|
|
97
99
|
const newGroupId = groupId || generateUniqueId( 'group' );
|
|
98
100
|
const newLabel = label || __( 'Default', 'elementor' );
|
|
99
101
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type V1Document } from '@elementor/editor-documents';
|
|
2
|
+
import { type V1Element, type V1ElementData } from '@elementor/editor-elements';
|
|
3
|
+
|
|
4
|
+
import { publishDraftComponentsInPageBeforeSave } from '../../sync/publish-draft-components-in-page-before-save';
|
|
5
|
+
import { type DocumentSaveStatus } from '../../types';
|
|
6
|
+
import { setComponentOverridablePropsSettingsBeforeSave } from '../sync/set-component-overridable-props-settings-before-save';
|
|
7
|
+
import { updateArchivedComponentBeforeSave } from '../sync/update-archived-component-before-save';
|
|
8
|
+
import { updateComponentTitleBeforeSave } from '../sync/update-component-title-before-save';
|
|
9
|
+
import { createComponentsBeforeSave } from './create-components-before-save';
|
|
10
|
+
|
|
11
|
+
type Options = {
|
|
12
|
+
container: V1Element & {
|
|
13
|
+
document: V1Document;
|
|
14
|
+
model: {
|
|
15
|
+
get: ( key: 'elements' ) => {
|
|
16
|
+
toJSON: () => V1ElementData[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
status: DocumentSaveStatus;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const beforeSave = ( { container, status }: Options ) => {
|
|
24
|
+
const elements = container?.model.get( 'elements' ).toJSON?.() ?? [];
|
|
25
|
+
|
|
26
|
+
return Promise.all( [
|
|
27
|
+
syncComponents( { elements, status } ),
|
|
28
|
+
setComponentOverridablePropsSettingsBeforeSave( { container } ),
|
|
29
|
+
] );
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// These operations run sequentially to prevent race conditions when multiple
|
|
33
|
+
// edits occur on the same component simultaneously.
|
|
34
|
+
// TODO: Consolidate these into a single PUT /components endpoint.
|
|
35
|
+
const syncComponents = async ( { elements, status }: { elements: V1ElementData[]; status: DocumentSaveStatus } ) => {
|
|
36
|
+
// This order is important - first update existing components, then create new components,
|
|
37
|
+
// Since new component validation depends on the existing components (preventing duplicate names).
|
|
38
|
+
await updateExistingComponentsBeforeSave( { elements, status } );
|
|
39
|
+
await createComponentsBeforeSave( { elements, status } );
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const updateExistingComponentsBeforeSave = async ( {
|
|
43
|
+
elements,
|
|
44
|
+
status,
|
|
45
|
+
}: {
|
|
46
|
+
elements: V1ElementData[];
|
|
47
|
+
status: DocumentSaveStatus;
|
|
48
|
+
} ) => {
|
|
49
|
+
await updateComponentTitleBeforeSave( status );
|
|
50
|
+
await updateArchivedComponentBeforeSave( status );
|
|
51
|
+
await publishDraftComponentsInPageBeforeSave( { elements, status } );
|
|
52
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getAllDescendants, type V1Element } from '@elementor/editor-elements';
|
|
2
|
-
import { registerDataHook } from '@elementor/editor-v1-adapters';
|
|
3
|
-
import {
|
|
2
|
+
import { type HookOptions, registerDataHook } from '@elementor/editor-v1-adapters';
|
|
3
|
+
import { __getState as getState } from '@elementor/store';
|
|
4
4
|
|
|
5
|
-
import { type ComponentsSlice, selectCurrentComponentId, selectOverridableProps
|
|
6
|
-
import {
|
|
5
|
+
import { type ComponentsSlice, selectCurrentComponentId, selectOverridableProps } from '../../store/store';
|
|
6
|
+
import { deleteOverridableProp } from '../store/actions/delete-overridable-prop';
|
|
7
7
|
|
|
8
8
|
type DeleteCommandArgs = {
|
|
9
9
|
container?: V1Element;
|
|
@@ -11,7 +11,14 @@ type DeleteCommandArgs = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export function initCleanupOverridablePropsOnDelete() {
|
|
14
|
-
|
|
14
|
+
// This hook is not a real dependency - it doesn't block the execution of the command in any case, only perform side effect.
|
|
15
|
+
// We use `dependency` and not `after` hook because the `after` hook doesn't include the children of a deleted container
|
|
16
|
+
// in the callback parameters (as they already were deleted).
|
|
17
|
+
registerDataHook( 'dependency', 'document/elements/delete', ( args: DeleteCommandArgs, options?: HookOptions ) => {
|
|
18
|
+
if ( isPartOfMoveCommand( options ) ) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
const state = getState() as ComponentsSlice | undefined;
|
|
16
23
|
|
|
17
24
|
if ( ! state ) {
|
|
@@ -50,25 +57,7 @@ export function initCleanupOverridablePropsOnDelete() {
|
|
|
50
57
|
return true;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
Object.entries( overridableProps.props ).filter( ( [ propKey ] ) => ! propKeysToDelete.includes( propKey ) )
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
let updatedGroups = overridableProps.groups;
|
|
58
|
-
for ( const propKey of propKeysToDelete ) {
|
|
59
|
-
updatedGroups = removePropFromAllGroups( updatedGroups, propKey );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
dispatch(
|
|
63
|
-
slice.actions.setOverridableProps( {
|
|
64
|
-
componentId: currentComponentId,
|
|
65
|
-
overridableProps: {
|
|
66
|
-
...overridableProps,
|
|
67
|
-
props: remainingProps,
|
|
68
|
-
groups: updatedGroups,
|
|
69
|
-
},
|
|
70
|
-
} )
|
|
71
|
-
);
|
|
60
|
+
deleteOverridableProp( { componentId: currentComponentId, propKey: propKeysToDelete, source: 'system' } );
|
|
72
61
|
|
|
73
62
|
return true;
|
|
74
63
|
} );
|
|
@@ -83,3 +72,14 @@ function collectDeletedElementIds( containers: V1Element[] ): string[] {
|
|
|
83
72
|
|
|
84
73
|
return elementIds;
|
|
85
74
|
}
|
|
75
|
+
|
|
76
|
+
function isPartOfMoveCommand( options?: HookOptions ): boolean {
|
|
77
|
+
// Skip cleanup if this delete is part of a move command
|
|
78
|
+
// Move = delete + create, and we don't want to delete the overridable prop in this case.
|
|
79
|
+
// See assets/dev/js/editor/document/elements/commands/move.js
|
|
80
|
+
const isMoveCommandInTrace =
|
|
81
|
+
options?.commandsCurrentTrace?.includes( 'document/elements/move' ) ||
|
|
82
|
+
options?.commandsCurrentTrace?.includes( 'document/repeater/move' );
|
|
83
|
+
|
|
84
|
+
return Boolean( isMoveCommandInTrace );
|
|
85
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { updateElementSettings, type V1ElementData } from '@elementor/editor-elements';
|
|
2
2
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
3
3
|
|
|
4
|
-
import { apiClient } from '
|
|
5
|
-
import { type ComponentInstanceProp } from '
|
|
6
|
-
import { selectUnpublishedComponents, slice } from '
|
|
7
|
-
import { type DocumentSaveStatus, type UnpublishedComponent } from '
|
|
4
|
+
import { apiClient } from '../../api';
|
|
5
|
+
import { type ComponentInstanceProp } from '../../prop-types/component-instance-prop-type';
|
|
6
|
+
import { selectUnpublishedComponents, slice } from '../../store/store';
|
|
7
|
+
import { type DocumentSaveStatus, type UnpublishedComponent } from '../../types';
|
|
8
8
|
|
|
9
9
|
export async function createComponentsBeforeSave( {
|
|
10
10
|
elements,
|
|
@@ -2,7 +2,7 @@ import { type V1Document } from '@elementor/editor-documents';
|
|
|
2
2
|
import { createElement, selectElement, type V1Element } from '@elementor/editor-elements';
|
|
3
3
|
import { registerDataHook } from '@elementor/editor-v1-adapters';
|
|
4
4
|
|
|
5
|
-
import { COMPONENT_DOCUMENT_TYPE } from '../
|
|
5
|
+
import { COMPONENT_DOCUMENT_TYPE } from '../consts';
|
|
6
6
|
import { isEditingComponent } from '../utils/is-editing-component';
|
|
7
7
|
|
|
8
8
|
const V4_DEFAULT_CONTAINER_TYPE = 'e-flexbox';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type V1Element, type V1ElementData } from '@elementor/editor-elements';
|
|
2
2
|
import { registerDataHook } from '@elementor/editor-v1-adapters';
|
|
3
3
|
|
|
4
|
-
import { type ExtendedWindow } from '
|
|
4
|
+
import { type ExtendedWindow } from '../../types';
|
|
5
5
|
import { isEditingComponent } from '../utils/is-editing-component';
|
|
6
6
|
import {
|
|
7
7
|
revertAllOverridablesInContainer,
|
|
@@ -2,8 +2,8 @@ import { type V1Document } from '@elementor/editor-documents';
|
|
|
2
2
|
import { type V1Element } from '@elementor/editor-elements';
|
|
3
3
|
import { __getState as getState } from '@elementor/store';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { selectOverridableProps } from '../../store/store';
|
|
6
|
+
import { COMPONENT_DOCUMENT_TYPE } from '../consts';
|
|
7
7
|
|
|
8
8
|
export const setComponentOverridablePropsSettingsBeforeSave = ( {
|
|
9
9
|
container,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type NotificationData, notify } from '@elementor/editor-notifications';
|
|
2
2
|
import { __getState as getState } from '@elementor/store';
|
|
3
3
|
|
|
4
|
-
import { apiClient } from '
|
|
5
|
-
import { selectArchivedThisSession } from '
|
|
6
|
-
import { type DocumentSaveStatus } from '
|
|
4
|
+
import { apiClient } from '../../api';
|
|
5
|
+
import { selectArchivedThisSession } from '../../store/store';
|
|
6
|
+
import { type DocumentSaveStatus } from '../../types';
|
|
7
7
|
|
|
8
8
|
const failedNotification = ( message: string ): NotificationData => ( {
|
|
9
9
|
type: 'error',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import { apiClient } from '
|
|
4
|
-
import { selectUpdatedComponentNames, slice } from '
|
|
5
|
-
import { type DocumentSaveStatus } from '
|
|
3
|
+
import { apiClient } from '../../api';
|
|
4
|
+
import { selectUpdatedComponentNames, slice } from '../../store/store';
|
|
5
|
+
import { type DocumentSaveStatus } from '../../types';
|
|
6
6
|
|
|
7
7
|
export const updateComponentTitleBeforeSave = async ( status: DocumentSaveStatus ) => {
|
|
8
8
|
const updatedComponentNames = selectUpdatedComponentNames( getState() );
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __getStore as getStore } from '@elementor/store';
|
|
2
2
|
|
|
3
|
-
import { type ComponentsSlice, selectCurrentComponentId } from '
|
|
3
|
+
import { type ComponentsSlice, selectCurrentComponentId } from '../../store/store';
|
|
4
4
|
|
|
5
5
|
export function isEditingComponent(): boolean {
|
|
6
6
|
const state = getStore()?.getState() as ComponentsSlice | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { replaceElement, type V1ElementData } from '@elementor/editor-elements';
|
|
2
|
+
|
|
3
|
+
import { type ComponentInstanceParams, createComponentModel } from '../../utils/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
|
+
};
|
|
@@ -8,22 +8,22 @@ import {
|
|
|
8
8
|
type V1ElementSettingsProps,
|
|
9
9
|
} from '@elementor/editor-elements';
|
|
10
10
|
|
|
11
|
-
import { COMPONENT_WIDGET_TYPE } from '
|
|
11
|
+
import { COMPONENT_WIDGET_TYPE } from '../../create-component-type';
|
|
12
12
|
import {
|
|
13
13
|
type ComponentInstanceOverrideProp,
|
|
14
14
|
componentInstanceOverridePropTypeUtil,
|
|
15
|
-
} from '
|
|
15
|
+
} from '../../prop-types/component-instance-override-prop-type';
|
|
16
16
|
import {
|
|
17
17
|
componentInstanceOverridesPropTypeUtil,
|
|
18
18
|
type ComponentInstanceOverridesPropValue,
|
|
19
|
-
} from '
|
|
19
|
+
} from '../../prop-types/component-instance-overrides-prop-type';
|
|
20
20
|
import {
|
|
21
21
|
type ComponentInstanceProp,
|
|
22
22
|
componentInstancePropTypeUtil,
|
|
23
23
|
type ComponentInstancePropValue,
|
|
24
|
-
} from '
|
|
25
|
-
import { componentOverridablePropTypeUtil } from '
|
|
26
|
-
import { isComponentInstance } from '
|
|
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
27
|
|
|
28
28
|
type RevertSettingsResult = {
|
|
29
29
|
hasChanges: boolean;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { deleteOverridableProp } from '../store/actions/delete-overridable-prop';
|
|
2
|
-
import { updateComponentSanitizedAttribute } from '../store/actions/update-component-sanitized-attribute';
|
|
1
|
+
import { deleteOverridableProp } from '../extended/store/actions/delete-overridable-prop';
|
|
2
|
+
import { updateComponentSanitizedAttribute } from '../extended/store/actions/update-component-sanitized-attribute';
|
|
3
3
|
import { useIsSanitizedComponent, useOverridableProps } from '../store/store';
|
|
4
4
|
import { type ComponentId, type OverridableProps } from '../types';
|
|
5
5
|
import { filterValidOverridableProps } from '../utils/filter-valid-overridable-props';
|
|
6
6
|
|
|
7
|
-
export function useSanitizeOverridableProps(
|
|
7
|
+
export function useSanitizeOverridableProps(
|
|
8
|
+
componentId: ComponentId | null,
|
|
9
|
+
// instanceElementId is used to find the component inner elements,
|
|
10
|
+
// and should be passed when editing component instance (not in component edit mode)
|
|
11
|
+
instanceElementId?: string
|
|
12
|
+
): OverridableProps | undefined {
|
|
8
13
|
const overridableProps = useOverridableProps( componentId );
|
|
9
14
|
const isSanitized = useIsSanitizedComponent( componentId, 'overridableProps' );
|
|
10
15
|
|
|
@@ -16,7 +21,7 @@ export function useSanitizeOverridableProps( componentId: ComponentId | null ):
|
|
|
16
21
|
return overridableProps;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
const filteredOverridableProps = filterValidOverridableProps( overridableProps );
|
|
24
|
+
const filteredOverridableProps = filterValidOverridableProps( overridableProps, instanceElementId );
|
|
20
25
|
|
|
21
26
|
const originalPropsArray = Object.entries( overridableProps.props ?? {} );
|
|
22
27
|
const propsToDelete = originalPropsArray.filter( ( [ key ] ) => ! filteredOverridableProps.props[ key ] );
|