@elementor/editor-components 3.35.0-389 → 3.35.0-390
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 +407 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +381 -143
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -22
- package/src/component-instance-transformer.ts +2 -2
- package/src/component-override-transformer.ts +2 -2
- package/src/components/component-properties-panel/component-properties-panel-content.tsx +4 -4
- package/src/components/control-label.tsx +15 -0
- package/src/components/instance-editing-panel/instance-editing-panel.tsx +27 -20
- package/src/components/instance-editing-panel/override-prop-control.tsx +207 -0
- package/src/components/instance-editing-panel/override-props-group.tsx +13 -7
- package/src/components/overridable-props/overridable-prop-control.tsx +23 -5
- package/src/components/overridable-props/overridable-prop-indicator.tsx +10 -6
- package/src/create-component-type.ts +4 -3
- package/src/hooks/regenerate-override-keys.ts +6 -4
- package/src/hooks/use-controls-by-widget-type.ts +40 -0
- package/src/prop-types/component-instance-override-prop-type.ts +0 -1
- package/src/prop-types/component-instance-overrides-prop-type.ts +5 -1
- package/src/prop-types/component-instance-prop-type.ts +2 -1
- package/src/store/actions/set-overridable-prop.ts +4 -1
- package/src/store/actions/update-overridable-prop-params.ts +58 -0
- package/src/store/actions/update-overridable-prop.ts +30 -38
- package/src/store/store.ts +8 -0
- package/src/sync/create-components-before-save.ts +9 -5
- package/src/types.ts +3 -20
- package/src/utils/get-component-ids.ts +11 -6
- package/src/utils/get-prop-type-for-component-override.ts +23 -0
- package/src/store/actions/update-overridable-prop-origin-value.ts +0 -37
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.35.0-
|
|
4
|
+
"version": "3.35.0-390",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,30 +40,30 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor": "3.35.0-
|
|
44
|
-
"@elementor/editor-canvas": "3.35.0-
|
|
45
|
-
"@elementor/editor-controls": "3.35.0-
|
|
46
|
-
"@elementor/editor-documents": "3.35.0-
|
|
47
|
-
"@elementor/editor-editing-panel": "3.35.0-
|
|
48
|
-
"@elementor/editor-elements": "3.35.0-
|
|
49
|
-
"@elementor/editor-elements-panel": "3.35.0-
|
|
50
|
-
"@elementor/editor-mcp": "3.35.0-
|
|
51
|
-
"@elementor/editor-panels": "3.35.0-
|
|
52
|
-
"@elementor/editor-props": "3.35.0-
|
|
53
|
-
"@elementor/editor-styles-repository": "3.35.0-
|
|
54
|
-
"@elementor/editor-ui": "3.35.0-
|
|
55
|
-
"@elementor/editor-v1-adapters": "3.35.0-
|
|
56
|
-
"@elementor/http-client": "3.35.0-
|
|
43
|
+
"@elementor/editor": "3.35.0-390",
|
|
44
|
+
"@elementor/editor-canvas": "3.35.0-390",
|
|
45
|
+
"@elementor/editor-controls": "3.35.0-390",
|
|
46
|
+
"@elementor/editor-documents": "3.35.0-390",
|
|
47
|
+
"@elementor/editor-editing-panel": "3.35.0-390",
|
|
48
|
+
"@elementor/editor-elements": "3.35.0-390",
|
|
49
|
+
"@elementor/editor-elements-panel": "3.35.0-390",
|
|
50
|
+
"@elementor/editor-mcp": "3.35.0-390",
|
|
51
|
+
"@elementor/editor-panels": "3.35.0-390",
|
|
52
|
+
"@elementor/editor-props": "3.35.0-390",
|
|
53
|
+
"@elementor/editor-styles-repository": "3.35.0-390",
|
|
54
|
+
"@elementor/editor-ui": "3.35.0-390",
|
|
55
|
+
"@elementor/editor-v1-adapters": "3.35.0-390",
|
|
56
|
+
"@elementor/http-client": "3.35.0-390",
|
|
57
57
|
"@elementor/icons": "^1.63.0",
|
|
58
|
-
"@elementor/mixpanel": "3.35.0-
|
|
59
|
-
"@elementor/query": "3.35.0-
|
|
60
|
-
"@elementor/schema": "3.35.0-
|
|
61
|
-
"@elementor/store": "3.35.0-
|
|
58
|
+
"@elementor/mixpanel": "3.35.0-390",
|
|
59
|
+
"@elementor/query": "3.35.0-390",
|
|
60
|
+
"@elementor/schema": "3.35.0-390",
|
|
61
|
+
"@elementor/store": "3.35.0-390",
|
|
62
62
|
"@elementor/ui": "1.36.17",
|
|
63
|
-
"@elementor/utils": "3.35.0-
|
|
63
|
+
"@elementor/utils": "3.35.0-390",
|
|
64
64
|
"@wordpress/i18n": "^5.13.0",
|
|
65
|
-
"@elementor/editor-notifications": "3.35.0-
|
|
66
|
-
"@elementor/editor-current-user": "3.35.0-
|
|
65
|
+
"@elementor/editor-notifications": "3.35.0-390",
|
|
66
|
+
"@elementor/editor-current-user": "3.35.0-390"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": "^18.3.1",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createTransformer, RenderContext } from '@elementor/editor-canvas';
|
|
2
2
|
import { __getState as getState } from '@elementor/store';
|
|
3
3
|
|
|
4
|
+
import { type ComponentInstanceOverrideProp } from './prop-types/component-instance-override-prop-type';
|
|
4
5
|
import { selectUnpublishedComponents } from './store/store';
|
|
5
|
-
import { type ComponentOverridePropValue } from './types';
|
|
6
6
|
import { getComponentDocumentData } from './utils/component-document-data';
|
|
7
7
|
|
|
8
8
|
type ComponentInstanceContext = {
|
|
@@ -19,7 +19,7 @@ export const componentInstanceTransformer = createTransformer(
|
|
|
19
19
|
overrides: overridesValue,
|
|
20
20
|
}: {
|
|
21
21
|
component_id: number | string;
|
|
22
|
-
overrides?:
|
|
22
|
+
overrides?: ComponentInstanceOverrideProp[];
|
|
23
23
|
} ) => {
|
|
24
24
|
const unpublishedComponents = selectUnpublishedComponents( getState() );
|
|
25
25
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createTransformer } from '@elementor/editor-canvas';
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type ComponentInstanceOverridePropValue } from './prop-types/component-instance-override-prop-type';
|
|
4
4
|
|
|
5
|
-
export const componentOverrideTransformer = createTransformer( ( override:
|
|
5
|
+
export const componentOverrideTransformer = createTransformer( ( override: ComponentInstanceOverridePropValue ) => {
|
|
6
6
|
const { override_key: key, override_value: overrideValue } = override;
|
|
7
7
|
|
|
8
8
|
return { [ key ]: overrideValue };
|
|
@@ -12,7 +12,7 @@ import { deleteOverridableGroup } from '../../store/actions/delete-overridable-g
|
|
|
12
12
|
import { deleteOverridableProp } from '../../store/actions/delete-overridable-prop';
|
|
13
13
|
import { reorderGroupProps } from '../../store/actions/reorder-group-props';
|
|
14
14
|
import { reorderOverridableGroups } from '../../store/actions/reorder-overridable-groups';
|
|
15
|
-
import {
|
|
15
|
+
import { updateOverridablePropParams } from '../../store/actions/update-overridable-prop-params';
|
|
16
16
|
import { useCurrentComponentId } from '../../store/store';
|
|
17
17
|
import { useOverridableProps } from '../component-panel-header/use-overridable-props';
|
|
18
18
|
import { PropertiesEmptyState } from './properties-empty-state';
|
|
@@ -85,10 +85,10 @@ export function ComponentPropertiesPanelContent( { onClose }: Props ) {
|
|
|
85
85
|
setDocumentModifiedStatus( true );
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
const handlePropertyUpdate = (
|
|
89
|
-
|
|
88
|
+
const handlePropertyUpdate = ( overrideKey: string, data: { label: string; group: string | null } ) => {
|
|
89
|
+
updateOverridablePropParams( {
|
|
90
90
|
componentId: currentComponentId,
|
|
91
|
-
|
|
91
|
+
overrideKey,
|
|
92
92
|
label: data.label,
|
|
93
93
|
groupId: data.group,
|
|
94
94
|
} );
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type PropsWithChildren } from 'react';
|
|
3
|
+
import { ControlAdornments, ControlFormLabel } from '@elementor/editor-controls';
|
|
4
|
+
import { type FormLabelProps, Stack } from '@elementor/ui';
|
|
5
|
+
|
|
6
|
+
type ControlLabelProps = FormLabelProps & PropsWithChildren< object >;
|
|
7
|
+
|
|
8
|
+
export const ControlLabel = ( { children, ...props }: ControlLabelProps ) => {
|
|
9
|
+
return (
|
|
10
|
+
<Stack direction="row" alignItems="center" justifyItems="start" gap={ 0.25 }>
|
|
11
|
+
<ControlFormLabel { ...props }>{ children }</ControlFormLabel>
|
|
12
|
+
<ControlAdornments />
|
|
13
|
+
</Stack>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ControlAdornmentsProvider } from '@elementor/editor-controls';
|
|
3
|
+
import { getFieldIndicators } from '@elementor/editor-editing-panel';
|
|
4
|
+
import { useSelectedElement } from '@elementor/editor-elements';
|
|
4
5
|
import { PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';
|
|
5
|
-
import { type NumberPropValue } from '@elementor/editor-props';
|
|
6
6
|
import { ComponentsIcon, PencilIcon } from '@elementor/icons';
|
|
7
|
-
import { __getState as getState } from '@elementor/store';
|
|
8
7
|
import { IconButton, Stack, Tooltip } from '@elementor/ui';
|
|
9
8
|
import { __ } from '@wordpress/i18n';
|
|
10
9
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { useComponentInstanceSettings } from '../../hooks/use-component-instance-settings';
|
|
11
|
+
import { useComponent, useOverridableProps } from '../../store/store';
|
|
13
12
|
import { type OverridablePropsGroup } from '../../types';
|
|
14
13
|
import { switchToComponent } from '../../utils/switch-to-component';
|
|
15
14
|
import { EmptyState } from './empty-state';
|
|
16
15
|
import { OverridePropsGroup } from './override-props-group';
|
|
17
16
|
|
|
18
17
|
export function InstanceEditingPanel() {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const componentId = ( componentInstancePropTypeUtil.extract( settings )?.component_id as NumberPropValue )?.value;
|
|
18
|
+
const settings = useComponentInstanceSettings();
|
|
19
|
+
const componentId = settings?.component_id?.value;
|
|
22
20
|
|
|
23
|
-
const
|
|
24
|
-
|
|
21
|
+
const overrides = settings?.overrides?.value;
|
|
22
|
+
|
|
23
|
+
const component = useComponent( componentId ?? null );
|
|
24
|
+
const overridableProps = useOverridableProps( componentId ?? null );
|
|
25
25
|
|
|
26
26
|
const componentInstanceId = useSelectedElement()?.element?.id ?? null;
|
|
27
27
|
|
|
@@ -58,15 +58,22 @@ export function InstanceEditingPanel() {
|
|
|
58
58
|
</Stack>
|
|
59
59
|
</PanelHeader>
|
|
60
60
|
<PanelBody>
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
<ControlAdornmentsProvider items={ getFieldIndicators( 'settings' ) }>
|
|
62
|
+
{ isEmpty ? (
|
|
63
|
+
<EmptyState onEditComponent={ handleEditComponent } />
|
|
64
|
+
) : (
|
|
65
|
+
<Stack direction="column" alignItems="stretch">
|
|
66
|
+
{ groups.map( ( group ) => (
|
|
67
|
+
<OverridePropsGroup
|
|
68
|
+
key={ group.id }
|
|
69
|
+
group={ group }
|
|
70
|
+
props={ overridableProps.props }
|
|
71
|
+
overrides={ overrides }
|
|
72
|
+
/>
|
|
73
|
+
) ) }
|
|
74
|
+
</Stack>
|
|
75
|
+
) }
|
|
76
|
+
</ControlAdornmentsProvider>
|
|
70
77
|
</PanelBody>
|
|
71
78
|
</>
|
|
72
79
|
);
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PropKeyProvider, PropProvider, useBoundProp } from '@elementor/editor-controls';
|
|
3
|
+
import {
|
|
4
|
+
controlsRegistry,
|
|
5
|
+
type ControlType,
|
|
6
|
+
createTopLevelObjectType,
|
|
7
|
+
SettingsField,
|
|
8
|
+
} from '@elementor/editor-editing-panel';
|
|
9
|
+
import { type Control } from '@elementor/editor-elements';
|
|
10
|
+
import { type PropValue, type TransformablePropValue } from '@elementor/editor-props';
|
|
11
|
+
import { Stack } from '@elementor/ui';
|
|
12
|
+
|
|
13
|
+
import { useControlsByWidgetType } from '../../hooks/use-controls-by-widget-type';
|
|
14
|
+
import {
|
|
15
|
+
type ComponentInstanceOverrideProp,
|
|
16
|
+
componentInstanceOverridePropTypeUtil,
|
|
17
|
+
} from '../../prop-types/component-instance-override-prop-type';
|
|
18
|
+
import {
|
|
19
|
+
componentInstanceOverridesPropTypeUtil,
|
|
20
|
+
type ComponentInstanceOverridesPropValue,
|
|
21
|
+
} from '../../prop-types/component-instance-overrides-prop-type';
|
|
22
|
+
import { componentInstancePropTypeUtil } from '../../prop-types/component-instance-prop-type';
|
|
23
|
+
import {
|
|
24
|
+
componentOverridablePropTypeUtil,
|
|
25
|
+
type ComponentOverridablePropValue,
|
|
26
|
+
} from '../../prop-types/component-overridable-prop-type';
|
|
27
|
+
import { updateOverridableProp } from '../../store/actions/update-overridable-prop';
|
|
28
|
+
import { useCurrentComponentId } from '../../store/store';
|
|
29
|
+
import { type OriginPropFields, type OverridableProp } from '../../types';
|
|
30
|
+
import { getPropTypeForComponentOverride } from '../../utils/get-prop-type-for-component-override';
|
|
31
|
+
import { ControlLabel } from '../control-label';
|
|
32
|
+
|
|
33
|
+
type Props = {
|
|
34
|
+
overridableProp: OverridableProp;
|
|
35
|
+
overrides?: ComponentInstanceOverridesPropValue;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type OverridesSchema = Record< string, NonNullable< ComponentInstanceOverridesPropValue >[ number ] >;
|
|
39
|
+
|
|
40
|
+
export function OverridePropControl( { overridableProp, overrides }: Props ) {
|
|
41
|
+
return (
|
|
42
|
+
<SettingsField bind="component_instance" propDisplayName={ overridableProp.label }>
|
|
43
|
+
<OverrideControl overridableProp={ overridableProp } overrides={ overrides } />
|
|
44
|
+
</SettingsField>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function OverrideControl( { overridableProp, overrides }: Props ) {
|
|
49
|
+
const componentId = useCurrentComponentId();
|
|
50
|
+
const { value: instanceValue, setValue: setInstanceValue } = useBoundProp( componentInstancePropTypeUtil );
|
|
51
|
+
const controls = useControlsByWidgetType(
|
|
52
|
+
overridableProp?.originPropFields?.widgetType ?? overridableProp.widgetType
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const propType = getPropTypeForComponentOverride( overridableProp );
|
|
56
|
+
|
|
57
|
+
if ( ! propType ) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const propTypeSchema = createTopLevelObjectType( {
|
|
62
|
+
schema: {
|
|
63
|
+
[ overridableProp.overrideKey ]: propType,
|
|
64
|
+
},
|
|
65
|
+
} );
|
|
66
|
+
|
|
67
|
+
const componentInstanceId = instanceValue.component_id?.value;
|
|
68
|
+
|
|
69
|
+
if ( ! componentInstanceId ) {
|
|
70
|
+
throw new Error( 'Component ID is required' );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const matchingOverride = getMatchingOverride( overrides, overridableProp.overrideKey );
|
|
74
|
+
|
|
75
|
+
const propValue = matchingOverride ? getPropValue( matchingOverride ) : overridableProp.originValue;
|
|
76
|
+
|
|
77
|
+
const value = {
|
|
78
|
+
[ overridableProp.overrideKey ]: propValue,
|
|
79
|
+
} as OverridesSchema;
|
|
80
|
+
|
|
81
|
+
const setValue = ( newValue: OverridesSchema ) => {
|
|
82
|
+
const newPropValue = newValue[ overridableProp.overrideKey ] as
|
|
83
|
+
| ComponentInstanceOverrideProp
|
|
84
|
+
| ComponentOverridablePropValue;
|
|
85
|
+
|
|
86
|
+
const newOverrideValue = createOverrideValue( overridableProp.overrideKey, newPropValue, componentInstanceId );
|
|
87
|
+
|
|
88
|
+
let newOverrides =
|
|
89
|
+
overrides?.map( ( override ) => ( override === matchingOverride ? newOverrideValue : override ) ) ?? [];
|
|
90
|
+
|
|
91
|
+
if ( ! matchingOverride ) {
|
|
92
|
+
newOverrides = [ ...newOverrides, newOverrideValue ];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setInstanceValue( {
|
|
96
|
+
...instanceValue,
|
|
97
|
+
overrides: componentInstanceOverridesPropTypeUtil.create( newOverrides ),
|
|
98
|
+
} );
|
|
99
|
+
|
|
100
|
+
const overridableValue = componentOverridablePropTypeUtil.extract( newOverrideValue );
|
|
101
|
+
if ( overridableValue && componentId ) {
|
|
102
|
+
if ( overridableProp.originPropFields ) {
|
|
103
|
+
updateOverridableProp( componentId, overridableValue, overridableProp.originPropFields );
|
|
104
|
+
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const { elType, widgetType, propKey } = overridableProp;
|
|
109
|
+
updateOverridableProp( componentId, overridableValue, { elType, widgetType, propKey } );
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<PropProvider
|
|
115
|
+
propType={ propTypeSchema }
|
|
116
|
+
value={ value }
|
|
117
|
+
setValue={ setValue }
|
|
118
|
+
isDisabled={ () => {
|
|
119
|
+
return false;
|
|
120
|
+
} }
|
|
121
|
+
>
|
|
122
|
+
<PropKeyProvider bind={ overridableProp.overrideKey }>
|
|
123
|
+
<Stack direction="column" gap={ 1 } mb={ 1.5 }>
|
|
124
|
+
<ControlLabel>{ overridableProp.label }</ControlLabel>
|
|
125
|
+
{ getControl( controls, overridableProp?.originPropFields ?? overridableProp ) }
|
|
126
|
+
</Stack>
|
|
127
|
+
</PropKeyProvider>
|
|
128
|
+
</PropProvider>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getPropValue( value: PropValue ): TransformablePropValue< string, unknown > | null {
|
|
133
|
+
const overridableValue = componentOverridablePropTypeUtil.extract( value );
|
|
134
|
+
|
|
135
|
+
if ( overridableValue ) {
|
|
136
|
+
// if overridable - return as is and let the control replacement handle the overridable value
|
|
137
|
+
return value as TransformablePropValue< string, unknown >;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if ( componentInstanceOverridePropTypeUtil.isValid( value ) ) {
|
|
141
|
+
return value.value.override_value as TransformablePropValue< string, unknown >;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getMatchingOverride(
|
|
148
|
+
overrides: ComponentInstanceOverridesPropValue,
|
|
149
|
+
overrideKey: string
|
|
150
|
+
): NonNullable< ComponentInstanceOverridesPropValue >[ number ] | null {
|
|
151
|
+
return (
|
|
152
|
+
overrides?.find( ( override ) => {
|
|
153
|
+
const overridableValue = componentOverridablePropTypeUtil.extract( override );
|
|
154
|
+
let comparedOverrideKey = null;
|
|
155
|
+
|
|
156
|
+
if ( overridableValue ) {
|
|
157
|
+
comparedOverrideKey = ( overridableValue.origin_value as ComponentInstanceOverrideProp )?.value
|
|
158
|
+
?.override_key;
|
|
159
|
+
} else {
|
|
160
|
+
comparedOverrideKey = override.value.override_key;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return comparedOverrideKey === overrideKey;
|
|
164
|
+
} ) ?? null
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function createOverrideValue(
|
|
169
|
+
overrideKey: string,
|
|
170
|
+
overrideValue: ComponentInstanceOverrideProp | ComponentOverridablePropValue,
|
|
171
|
+
componentId: number
|
|
172
|
+
): NonNullable< ComponentInstanceOverridesPropValue >[ number ] {
|
|
173
|
+
const overridableValue = componentOverridablePropTypeUtil.extract( overrideValue );
|
|
174
|
+
|
|
175
|
+
if ( overridableValue ) {
|
|
176
|
+
const innerOverride = componentInstanceOverridePropTypeUtil.create( {
|
|
177
|
+
override_key: overrideKey,
|
|
178
|
+
override_value: overridableValue.origin_value,
|
|
179
|
+
schema_source: {
|
|
180
|
+
type: 'component',
|
|
181
|
+
id: componentId,
|
|
182
|
+
},
|
|
183
|
+
} );
|
|
184
|
+
|
|
185
|
+
return componentOverridablePropTypeUtil.create( {
|
|
186
|
+
override_key: overridableValue.override_key,
|
|
187
|
+
origin_value: innerOverride,
|
|
188
|
+
} );
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return componentInstanceOverridePropTypeUtil.create( {
|
|
192
|
+
override_key: overrideKey,
|
|
193
|
+
override_value: overrideValue,
|
|
194
|
+
schema_source: {
|
|
195
|
+
type: 'component',
|
|
196
|
+
id: componentId,
|
|
197
|
+
},
|
|
198
|
+
} );
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function getControl( controls: Record< string, Control >, originPropFields: OriginPropFields ) {
|
|
202
|
+
const ControlComponent = controlsRegistry.get( controls[ originPropFields.propKey ].value.type as ControlType );
|
|
203
|
+
|
|
204
|
+
const controlProps = controls[ originPropFields.propKey ].value.props;
|
|
205
|
+
|
|
206
|
+
return <ControlComponent { ...controlProps } />;
|
|
207
|
+
}
|
|
@@ -2,16 +2,19 @@ import * as React from 'react';
|
|
|
2
2
|
import { useId } from 'react';
|
|
3
3
|
import { useStateByElement } from '@elementor/editor-editing-panel';
|
|
4
4
|
import { CollapseIcon } from '@elementor/editor-ui';
|
|
5
|
-
import { Collapse, ListItemButton, ListItemText, Stack } from '@elementor/ui';
|
|
5
|
+
import { Box, Collapse, ListItemButton, ListItemText, Stack } from '@elementor/ui';
|
|
6
6
|
|
|
7
|
+
import { type ComponentInstanceOverridesPropValue } from '../../prop-types/component-instance-overrides-prop-type';
|
|
7
8
|
import { type OverridableProp, type OverridablePropsGroup } from '../../types';
|
|
9
|
+
import { OverridePropControl } from './override-prop-control';
|
|
8
10
|
|
|
9
11
|
type Props = {
|
|
10
12
|
group: OverridablePropsGroup;
|
|
11
13
|
props: Record< string, OverridableProp >;
|
|
14
|
+
overrides: ComponentInstanceOverridesPropValue;
|
|
12
15
|
};
|
|
13
16
|
|
|
14
|
-
export function OverridePropsGroup( { group, props }: Props ) {
|
|
17
|
+
export function OverridePropsGroup( { group, props, overrides }: Props ) {
|
|
15
18
|
const [ isOpen, setIsOpen ] = useStateByElement( group.id, true );
|
|
16
19
|
|
|
17
20
|
const handleClick = () => {
|
|
@@ -25,7 +28,7 @@ export function OverridePropsGroup( { group, props }: Props ) {
|
|
|
25
28
|
const title = group.label;
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
|
-
|
|
31
|
+
<Box aria-label={ `${ title } section` }>
|
|
29
32
|
<ListItemButton
|
|
30
33
|
id={ labelId }
|
|
31
34
|
aria-controls={ contentId }
|
|
@@ -45,12 +48,15 @@ export function OverridePropsGroup( { group, props }: Props ) {
|
|
|
45
48
|
</ListItemButton>
|
|
46
49
|
<Collapse id={ contentId } aria-labelledby={ labelId } in={ isOpen } timeout="auto">
|
|
47
50
|
<Stack direction="column" gap={ 1 } p={ 2 }>
|
|
48
|
-
{ group.props.map( (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
{ group.props.map( ( overrideKey ) => (
|
|
52
|
+
<OverridePropControl
|
|
53
|
+
key={ overrideKey }
|
|
54
|
+
overridableProp={ props[ overrideKey ] }
|
|
55
|
+
overrides={ overrides }
|
|
56
|
+
/>
|
|
51
57
|
) ) }
|
|
52
58
|
</Stack>
|
|
53
59
|
</Collapse>
|
|
54
|
-
|
|
60
|
+
</Box>
|
|
55
61
|
);
|
|
56
62
|
}
|
|
@@ -4,13 +4,15 @@ import { ControlReplacementsProvider, PropKeyProvider, PropProvider, useBoundPro
|
|
|
4
4
|
import { createTopLevelObjectType, useElement } from '@elementor/editor-editing-panel';
|
|
5
5
|
import { type PropValue } from '@elementor/editor-props';
|
|
6
6
|
|
|
7
|
+
import { type ComponentInstanceOverridePropValue } from '../../prop-types/component-instance-override-prop-type';
|
|
7
8
|
import {
|
|
8
9
|
componentOverridablePropTypeUtil,
|
|
9
10
|
type ComponentOverridablePropValue,
|
|
10
11
|
} from '../../prop-types/component-overridable-prop-type';
|
|
11
12
|
import { OverridablePropProvider } from '../../provider/overridable-prop-context';
|
|
12
|
-
import {
|
|
13
|
-
import { useCurrentComponentId } from '../../store/store';
|
|
13
|
+
import { updateOverridableProp } from '../../store/actions/update-overridable-prop';
|
|
14
|
+
import { useCurrentComponentId, useOverridableProps } from '../../store/store';
|
|
15
|
+
import { getPropTypeForComponentOverride } from '../../utils/get-prop-type-for-component-override';
|
|
14
16
|
|
|
15
17
|
export function OverridablePropControl< T extends object >( {
|
|
16
18
|
OriginalControl,
|
|
@@ -20,6 +22,7 @@ export function OverridablePropControl< T extends object >( {
|
|
|
20
22
|
|
|
21
23
|
const { value, bind, setValue, placeholder, ...propContext } = useBoundProp( componentOverridablePropTypeUtil );
|
|
22
24
|
const componentId = useCurrentComponentId();
|
|
25
|
+
const overridableProps = useOverridableProps( componentId );
|
|
23
26
|
|
|
24
27
|
if ( ! componentId ) {
|
|
25
28
|
return null;
|
|
@@ -29,6 +32,8 @@ export function OverridablePropControl< T extends object >( {
|
|
|
29
32
|
throw new Error( 'Override key is required' );
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
const isComponentInstance = elementType.key === 'e-component';
|
|
36
|
+
|
|
32
37
|
const setOverridableValue = ( newValue: Record< typeof bind, PropValue | null > ) => {
|
|
33
38
|
const propValue = {
|
|
34
39
|
...value,
|
|
@@ -36,15 +41,26 @@ export function OverridablePropControl< T extends object >( {
|
|
|
36
41
|
} as ComponentOverridablePropValue;
|
|
37
42
|
|
|
38
43
|
setValue( propValue );
|
|
39
|
-
|
|
44
|
+
updateOverridableProp( componentId, propValue );
|
|
40
45
|
};
|
|
41
46
|
|
|
47
|
+
const defaultPropType = elementType.propsSchema[ bind ];
|
|
48
|
+
|
|
42
49
|
const propType = createTopLevelObjectType( {
|
|
43
50
|
schema: {
|
|
44
|
-
[ bind ]:
|
|
51
|
+
[ bind ]:
|
|
52
|
+
isComponentInstance && overridableProps
|
|
53
|
+
? getPropTypeForComponentOverride( overridableProps.props[ value.override_key ] ) ?? defaultPropType
|
|
54
|
+
: defaultPropType,
|
|
45
55
|
},
|
|
46
56
|
} );
|
|
47
57
|
|
|
58
|
+
const propValue = (
|
|
59
|
+
isComponentInstance
|
|
60
|
+
? ( value.origin_value?.value as ComponentInstanceOverridePropValue ).override_value
|
|
61
|
+
: value.origin_value
|
|
62
|
+
) as PropValue;
|
|
63
|
+
|
|
48
64
|
const objectPlaceholder: Record< string, PropValue > | undefined = placeholder
|
|
49
65
|
? { [ bind ]: placeholder }
|
|
50
66
|
: undefined;
|
|
@@ -55,7 +71,9 @@ export function OverridablePropControl< T extends object >( {
|
|
|
55
71
|
{ ...propContext }
|
|
56
72
|
propType={ propType }
|
|
57
73
|
setValue={ setOverridableValue }
|
|
58
|
-
value={ {
|
|
74
|
+
value={ {
|
|
75
|
+
[ bind ]: propValue,
|
|
76
|
+
} }
|
|
59
77
|
placeholder={ objectPlaceholder }
|
|
60
78
|
>
|
|
61
79
|
<PropKeyProvider bind={ bind }>
|
|
@@ -3,14 +3,13 @@ import { useBoundProp } from '@elementor/editor-controls';
|
|
|
3
3
|
import { useElement } from '@elementor/editor-editing-panel';
|
|
4
4
|
import { getWidgetsCache } from '@elementor/editor-elements';
|
|
5
5
|
import { type TransformablePropValue } from '@elementor/editor-props';
|
|
6
|
-
import { __getState as getState } from '@elementor/store';
|
|
7
6
|
import { bindPopover, bindTrigger, Popover, Tooltip, usePopupState } from '@elementor/ui';
|
|
8
7
|
import { __ } from '@wordpress/i18n';
|
|
9
8
|
|
|
10
9
|
import { componentOverridablePropTypeUtil } from '../../prop-types/component-overridable-prop-type';
|
|
11
10
|
import { useOverridablePropValue } from '../../provider/overridable-prop-context';
|
|
12
11
|
import { setOverridableProp } from '../../store/actions/set-overridable-prop';
|
|
13
|
-
import {
|
|
12
|
+
import { useCurrentComponentId, useOverridableProps } from '../../store/store';
|
|
14
13
|
import { type OverridableProps } from '../../types';
|
|
15
14
|
import { Indicator } from './indicator';
|
|
16
15
|
import { OverridablePropForm } from './overridable-prop-form';
|
|
@@ -21,13 +20,12 @@ const FORBIDDEN_KEYS = [ '_cssid', 'attributes' ];
|
|
|
21
20
|
export function OverridablePropIndicator() {
|
|
22
21
|
const { bind } = useBoundProp();
|
|
23
22
|
const componentId = useCurrentComponentId();
|
|
23
|
+
const overridableProps = useOverridableProps( componentId );
|
|
24
24
|
|
|
25
|
-
if ( ! isPropAllowed( bind ) || ! componentId ) {
|
|
25
|
+
if ( ! isPropAllowed( bind ) || ! componentId || ! overridableProps ) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const overridableProps = selectOverridableProps( getState(), componentId );
|
|
30
|
-
|
|
31
29
|
return <Content componentId={ componentId } overridableProps={ overridableProps } />;
|
|
32
30
|
}
|
|
33
31
|
|
|
@@ -63,7 +61,12 @@ export function Content( { componentId, overridableProps }: Props ) {
|
|
|
63
61
|
const { elType } = getWidgetsCache()?.[ elementType.key ] ?? { elType: 'widget' };
|
|
64
62
|
|
|
65
63
|
const handleSubmit = ( { label, group }: { label: string; group: string | null } ) => {
|
|
66
|
-
const
|
|
64
|
+
const propTypeDefault = propType.default ?? {};
|
|
65
|
+
const originValue = ( ! overridableValue ? value : overridableValue?.origin_value ) ?? propTypeDefault;
|
|
66
|
+
|
|
67
|
+
const matchingOverridableProp = overridableValue
|
|
68
|
+
? overridableProps?.props?.[ overridableValue.override_key ]
|
|
69
|
+
: undefined;
|
|
67
70
|
|
|
68
71
|
const overridablePropConfig = setOverridableProp( {
|
|
69
72
|
componentId,
|
|
@@ -75,6 +78,7 @@ export function Content( { componentId, overridableProps }: Props ) {
|
|
|
75
78
|
elType: elType ?? 'widget',
|
|
76
79
|
widgetType: elementType.key,
|
|
77
80
|
originValue,
|
|
81
|
+
originPropFields: matchingOverridableProp?.originPropFields,
|
|
78
82
|
} );
|
|
79
83
|
|
|
80
84
|
if ( ! overridableValue && overridablePropConfig ) {
|
|
@@ -11,7 +11,8 @@ import { getCurrentDocument } from '@elementor/editor-documents';
|
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
12
|
|
|
13
13
|
import { apiClient } from './api';
|
|
14
|
-
import { type
|
|
14
|
+
import { type ComponentInstanceProp } from './prop-types/component-instance-prop-type';
|
|
15
|
+
import { type ExtendedWindow } from './types';
|
|
15
16
|
import { switchToComponent } from './utils/switch-to-component';
|
|
16
17
|
import { trackComponentEvent } from './utils/tracking';
|
|
17
18
|
|
|
@@ -130,7 +131,7 @@ function createComponentView(
|
|
|
130
131
|
|
|
131
132
|
getComponentId() {
|
|
132
133
|
const componentInstance = (
|
|
133
|
-
this.options?.model?.get( 'settings' )?.get( 'component_instance' ) as
|
|
134
|
+
this.options?.model?.get( 'settings' )?.get( 'component_instance' ) as ComponentInstanceProp
|
|
134
135
|
)?.value;
|
|
135
136
|
|
|
136
137
|
return componentInstance.component_id.value;
|
|
@@ -186,7 +187,7 @@ function createComponentView(
|
|
|
186
187
|
if ( ! isAllowedToSwitchDocument ) {
|
|
187
188
|
options.showLockedByModal?.( lockedBy || '' );
|
|
188
189
|
} else {
|
|
189
|
-
switchToComponent( this.getComponentId(), this.model.get( 'id' ) );
|
|
190
|
+
switchToComponent( this.getComponentId() as number, this.model.get( 'id' ) );
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
@@ -3,12 +3,14 @@ import { registerDataHook } from '@elementor/editor-v1-adapters';
|
|
|
3
3
|
import { generateUniqueId } from '@elementor/utils';
|
|
4
4
|
|
|
5
5
|
import { componentInstanceOverridePropTypeUtil } from '../prop-types/component-instance-override-prop-type';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
componentInstanceOverridesPropTypeUtil,
|
|
8
|
+
type ComponentInstanceOverridesPropValue,
|
|
9
|
+
} from '../prop-types/component-instance-overrides-prop-type';
|
|
7
10
|
import {
|
|
8
11
|
componentInstancePropTypeUtil,
|
|
9
12
|
type ComponentInstancePropValue,
|
|
10
13
|
} from '../prop-types/component-instance-prop-type';
|
|
11
|
-
import { type ComponentOverride } from '../types';
|
|
12
14
|
import { isComponentInstance } from '../utils/is-component-instance';
|
|
13
15
|
|
|
14
16
|
export function initRegenerateOverrideKeys() {
|
|
@@ -63,7 +65,7 @@ function regenerateOverrideKeys( element: V1Element ) {
|
|
|
63
65
|
const componentInstance = settings.component_instance;
|
|
64
66
|
const overrides = componentInstance.value.overrides;
|
|
65
67
|
|
|
66
|
-
const newOverrides = overrides.value.map( ( override
|
|
68
|
+
const newOverrides = overrides.value.map( ( override ) => {
|
|
67
69
|
if ( ! componentInstanceOverridePropTypeUtil.isValid( override ) ) {
|
|
68
70
|
return override;
|
|
69
71
|
}
|
|
@@ -97,7 +99,7 @@ function regenerateOverrideKeys( element: V1Element ) {
|
|
|
97
99
|
|
|
98
100
|
function hasOverrides( settings: Record< string, unknown > ): settings is {
|
|
99
101
|
component_instance: NonNullable< ComponentInstancePropValue > & {
|
|
100
|
-
value: { overrides: { $$type: string; value:
|
|
102
|
+
value: { overrides: { $$type: string; value: NonNullable< ComponentInstanceOverridesPropValue >[] } };
|
|
101
103
|
};
|
|
102
104
|
} {
|
|
103
105
|
if ( ! componentInstancePropTypeUtil.isValid( settings?.component_instance ) ) {
|