@elementor/editor-editing-panel 1.47.0 → 1.48.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/CHANGELOG.md +37 -0
- package/dist/index.js +431 -348
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +433 -354
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -14
- package/src/components/style-sections/border-section/border-field.tsx +14 -7
- package/src/components/style-sections/effects-section/effects-section.tsx +12 -3
- package/src/components/style-sections/layout-section/flex-order-field.tsx +24 -18
- package/src/components/style-sections/layout-section/flex-size-field.tsx +14 -16
- package/src/components/style-sections/layout-section/layout-section.tsx +9 -2
- package/src/components/style-sections/layout-section/utils/rotated-icon.tsx +6 -1
- package/src/components/style-sections/position-section/position-section.tsx +19 -8
- package/src/components/style-sections/size-section/size-section.tsx +4 -1
- package/src/components/style-sections/typography-section/text-stroke-field.tsx +3 -1
- package/src/components/style-sections/typography-section/typography-section.tsx +6 -1
- package/src/components/style-tab.tsx +1 -1
- package/src/controls-registry/settings-field.tsx +21 -5
- package/src/controls-registry/styles-field.tsx +5 -3
- package/src/hooks/use-styles-field.ts +3 -4
- package/src/hooks/use-styles-fields.ts +141 -73
- package/src/init.ts +0 -6
|
@@ -1,61 +1,38 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
createElementStyle,
|
|
4
|
-
type CreateElementStyleArgs,
|
|
5
|
-
deleteElementStyle,
|
|
6
|
-
type ElementID,
|
|
7
|
-
getElementLabel,
|
|
8
|
-
} from '@elementor/editor-elements';
|
|
2
|
+
import { createElementStyle, deleteElementStyle, type ElementID, getElementLabel } from '@elementor/editor-elements';
|
|
9
3
|
import type { Props } from '@elementor/editor-props';
|
|
10
4
|
import { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
11
|
-
import { type StylesProvider } from '@elementor/editor-styles-repository';
|
|
5
|
+
import { isElementsStylesProvider, type StylesProvider } from '@elementor/editor-styles-repository';
|
|
12
6
|
import { ELEMENTS_STYLES_RESERVED_LABEL } from '@elementor/editor-styles-repository';
|
|
13
|
-
import { undoable } from '@elementor/editor-v1-adapters';
|
|
7
|
+
import { isExperimentActive, undoable } from '@elementor/editor-v1-adapters';
|
|
14
8
|
import { __ } from '@wordpress/i18n';
|
|
15
9
|
|
|
16
10
|
import { useClassesProp } from '../contexts/classes-prop-context';
|
|
17
11
|
import { useElement } from '../contexts/element-context';
|
|
18
12
|
import { useStyle } from '../contexts/style-context';
|
|
19
13
|
import { StyleNotFoundUnderProviderError, StylesProviderCannotUpdatePropsError } from '../errors';
|
|
14
|
+
import { EXPERIMENTAL_FEATURES } from '../sync/experiments-flags';
|
|
20
15
|
import { useStylesRerender } from './use-styles-rerender';
|
|
21
16
|
|
|
22
17
|
export function useStylesFields< T extends Props >( propNames: ( keyof T & string )[] ) {
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const {
|
|
19
|
+
element: { id: elementId },
|
|
20
|
+
} = useElement();
|
|
21
|
+
const { id: styleId, meta, provider, canEdit } = useStyle();
|
|
26
22
|
|
|
27
|
-
const undoableUpdateStyle = useUndoableUpdateStyle();
|
|
28
|
-
const undoableCreateElementStyle = useUndoableCreateElementStyle();
|
|
23
|
+
const undoableUpdateStyle = useUndoableUpdateStyle( { elementId, meta } );
|
|
24
|
+
const undoableCreateElementStyle = useUndoableCreateElementStyle( { elementId, meta } );
|
|
29
25
|
|
|
30
26
|
useStylesRerender();
|
|
31
27
|
|
|
32
|
-
const values = getProps< T >( {
|
|
33
|
-
elementId: element.id,
|
|
34
|
-
styleId: id,
|
|
35
|
-
provider,
|
|
36
|
-
meta,
|
|
37
|
-
propNames,
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
const setValues = ( props: T ) => {
|
|
41
|
-
if ( id === null ) {
|
|
42
|
-
undoableCreateElementStyle( {
|
|
43
|
-
elementId: element.id,
|
|
44
|
-
classesProp,
|
|
45
|
-
meta,
|
|
46
|
-
props,
|
|
47
|
-
} );
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
28
|
+
const values = getProps< T >( { elementId, styleId, provider, meta, propNames } );
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} );
|
|
30
|
+
const setValues = ( props: T, { history: { propDisplayName } }: { history: { propDisplayName: string } } ) => {
|
|
31
|
+
if ( styleId === null ) {
|
|
32
|
+
undoableCreateElementStyle( { props, propDisplayName } );
|
|
33
|
+
} else {
|
|
34
|
+
undoableUpdateStyle( { provider, styleId, props, propDisplayName } );
|
|
35
|
+
}
|
|
59
36
|
};
|
|
60
37
|
|
|
61
38
|
return { values, setValues, canEdit };
|
|
@@ -91,52 +68,78 @@ function getProps< T extends Props >( { styleId, elementId, provider, meta, prop
|
|
|
91
68
|
) as NullableValues< T >;
|
|
92
69
|
}
|
|
93
70
|
|
|
94
|
-
type UndoableCreateElementStyleArgs =
|
|
71
|
+
type UndoableCreateElementStyleArgs = {
|
|
72
|
+
props: Props;
|
|
73
|
+
propDisplayName: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function useUndoableCreateElementStyle( {
|
|
77
|
+
elementId,
|
|
78
|
+
meta,
|
|
79
|
+
}: {
|
|
80
|
+
elementId: ElementID;
|
|
81
|
+
meta: StyleDefinitionVariant[ 'meta' ];
|
|
82
|
+
} ) {
|
|
83
|
+
const classesProp = useClassesProp();
|
|
95
84
|
|
|
96
|
-
function useUndoableCreateElementStyle() {
|
|
97
85
|
return useMemo( () => {
|
|
86
|
+
const isVersion331Active = isExperimentActive( EXPERIMENTAL_FEATURES.V_3_31 );
|
|
87
|
+
|
|
88
|
+
const createStyleArgs = { elementId, classesProp, meta, label: ELEMENTS_STYLES_RESERVED_LABEL };
|
|
89
|
+
|
|
98
90
|
return undoable(
|
|
99
91
|
{
|
|
100
|
-
do: (
|
|
101
|
-
return createElementStyle( {
|
|
102
|
-
...payload,
|
|
103
|
-
label: ELEMENTS_STYLES_RESERVED_LABEL,
|
|
104
|
-
} );
|
|
92
|
+
do: ( { props }: UndoableCreateElementStyleArgs ) => {
|
|
93
|
+
return createElementStyle( { ...createStyleArgs, props } );
|
|
105
94
|
},
|
|
106
95
|
|
|
107
|
-
undo: (
|
|
96
|
+
undo: ( _, styleId ) => {
|
|
108
97
|
deleteElementStyle( elementId, styleId );
|
|
109
98
|
},
|
|
110
99
|
|
|
111
|
-
redo: (
|
|
112
|
-
return createElementStyle( {
|
|
113
|
-
...payload,
|
|
114
|
-
styleId,
|
|
115
|
-
label: ELEMENTS_STYLES_RESERVED_LABEL,
|
|
116
|
-
} );
|
|
100
|
+
redo: ( { props }, styleId ) => {
|
|
101
|
+
return createElementStyle( { ...createStyleArgs, props, styleId } );
|
|
117
102
|
},
|
|
118
103
|
},
|
|
119
104
|
{
|
|
120
|
-
title: (
|
|
121
|
-
|
|
105
|
+
title: () => {
|
|
106
|
+
if ( isVersion331Active ) {
|
|
107
|
+
return localStyleHistoryTitlesV331.title( { elementId } );
|
|
108
|
+
}
|
|
109
|
+
return historyTitlesV330.title( { elementId } );
|
|
110
|
+
},
|
|
111
|
+
subtitle: ( { propDisplayName } ) => {
|
|
112
|
+
if ( isVersion331Active ) {
|
|
113
|
+
return localStyleHistoryTitlesV331.subtitle( { propDisplayName } );
|
|
114
|
+
}
|
|
115
|
+
return historyTitlesV330.subtitle;
|
|
116
|
+
},
|
|
122
117
|
}
|
|
123
118
|
);
|
|
124
|
-
}, [] );
|
|
119
|
+
}, [ classesProp, elementId, meta ] );
|
|
125
120
|
}
|
|
126
121
|
|
|
127
122
|
type UndoableUpdateStyleArgs = {
|
|
128
|
-
elementId: ElementID;
|
|
129
123
|
styleId: StyleDefinition[ 'id' ];
|
|
130
124
|
provider: StylesProvider;
|
|
131
|
-
meta: StyleDefinitionVariant[ 'meta' ];
|
|
132
125
|
props: Props;
|
|
126
|
+
propDisplayName: string;
|
|
133
127
|
};
|
|
134
128
|
|
|
135
|
-
function useUndoableUpdateStyle(
|
|
129
|
+
function useUndoableUpdateStyle( {
|
|
130
|
+
elementId,
|
|
131
|
+
meta,
|
|
132
|
+
}: {
|
|
133
|
+
elementId: ElementID;
|
|
134
|
+
|
|
135
|
+
meta: StyleDefinitionVariant[ 'meta' ];
|
|
136
|
+
} ) {
|
|
136
137
|
return useMemo( () => {
|
|
138
|
+
const isVersion331Active = isExperimentActive( EXPERIMENTAL_FEATURES.V_3_31 );
|
|
139
|
+
|
|
137
140
|
return undoable(
|
|
138
141
|
{
|
|
139
|
-
do: ( {
|
|
142
|
+
do: ( { provider, styleId, props }: UndoableUpdateStyleArgs ) => {
|
|
140
143
|
if ( ! provider.actions.updateProps ) {
|
|
141
144
|
throw new StylesProviderCannotUpdatePropsError( {
|
|
142
145
|
context: { providerKey: provider.getKey() },
|
|
@@ -147,28 +150,41 @@ function useUndoableUpdateStyle() {
|
|
|
147
150
|
|
|
148
151
|
const prevProps = getCurrentProps( style, meta );
|
|
149
152
|
|
|
150
|
-
provider.actions.updateProps(
|
|
151
|
-
{
|
|
152
|
-
id: styleId,
|
|
153
|
-
meta,
|
|
154
|
-
props,
|
|
155
|
-
},
|
|
156
|
-
{ elementId }
|
|
157
|
-
);
|
|
153
|
+
provider.actions.updateProps( { id: styleId, meta, props }, { elementId } );
|
|
158
154
|
|
|
159
155
|
return prevProps;
|
|
160
156
|
},
|
|
161
157
|
|
|
162
|
-
undo: ( {
|
|
158
|
+
undo: ( { provider, styleId }, prevProps ) => {
|
|
163
159
|
provider.actions.updateProps?.( { id: styleId, meta, props: prevProps }, { elementId } );
|
|
164
160
|
},
|
|
165
161
|
},
|
|
166
162
|
{
|
|
167
|
-
title: ( {
|
|
168
|
-
|
|
163
|
+
title: ( { provider } ) => {
|
|
164
|
+
if ( isVersion331Active ) {
|
|
165
|
+
const isLocal = isElementsStylesProvider( provider.getKey() );
|
|
166
|
+
|
|
167
|
+
if ( isLocal ) {
|
|
168
|
+
return localStyleHistoryTitlesV331.title( { elementId } );
|
|
169
|
+
}
|
|
170
|
+
return defaultHistoryTitlesV331.title( { provider } );
|
|
171
|
+
}
|
|
172
|
+
return historyTitlesV330.title( { elementId } );
|
|
173
|
+
},
|
|
174
|
+
subtitle: ( { provider, styleId, propDisplayName } ) => {
|
|
175
|
+
if ( isVersion331Active ) {
|
|
176
|
+
const isLocal = isElementsStylesProvider( provider.getKey() );
|
|
177
|
+
|
|
178
|
+
if ( isLocal ) {
|
|
179
|
+
return localStyleHistoryTitlesV331.subtitle( { propDisplayName } );
|
|
180
|
+
}
|
|
181
|
+
return defaultHistoryTitlesV331.subtitle( { provider, styleId, elementId, propDisplayName } );
|
|
182
|
+
}
|
|
183
|
+
return historyTitlesV330.subtitle;
|
|
184
|
+
},
|
|
169
185
|
}
|
|
170
186
|
);
|
|
171
|
-
}, [] );
|
|
187
|
+
}, [ elementId, meta ] );
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
function getCurrentProps( style: StyleDefinition | null, meta: StyleDefinitionVariant[ 'meta' ] ) {
|
|
@@ -182,3 +198,55 @@ function getCurrentProps( style: StyleDefinition | null, meta: StyleDefinitionVa
|
|
|
182
198
|
|
|
183
199
|
return structuredClone( props );
|
|
184
200
|
}
|
|
201
|
+
|
|
202
|
+
const historyTitlesV330 = {
|
|
203
|
+
title: ( { elementId }: { elementId: ElementID } ) => getElementLabel( elementId ),
|
|
204
|
+
subtitle: __( 'Style edited', 'elementor' ),
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
type DefaultHistoryTitleV331Args = {
|
|
208
|
+
provider: StylesProvider;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
type DefaultHistorySubtitleV331Args = {
|
|
212
|
+
provider: StylesProvider;
|
|
213
|
+
styleId: StyleDefinition[ 'id' ];
|
|
214
|
+
elementId: ElementID;
|
|
215
|
+
propDisplayName: string;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const defaultHistoryTitlesV331 = {
|
|
219
|
+
title: ( { provider }: DefaultHistoryTitleV331Args ) => {
|
|
220
|
+
const providerLabel = provider.labels?.singular;
|
|
221
|
+
return providerLabel ? capitalize( providerLabel ) : __( 'Style', 'elementor' );
|
|
222
|
+
},
|
|
223
|
+
subtitle: ( { provider, styleId, elementId, propDisplayName }: DefaultHistorySubtitleV331Args ) => {
|
|
224
|
+
const styleLabel = provider.actions.get( styleId, { elementId } )?.label;
|
|
225
|
+
|
|
226
|
+
if ( ! styleLabel ) {
|
|
227
|
+
throw new Error( `Style ${ styleId } not found` );
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// translators: %s$1 is the style label, %s$2 is the name of the style property being edited
|
|
231
|
+
return __( `%s$1 %s$2 edited`, 'elementor' ).replace( '%s$1', styleLabel ).replace( '%s$2', propDisplayName );
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
type LocalStyleHistoryTitleV331Args = {
|
|
236
|
+
elementId: ElementID;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
type LocalStyleHistorySubtitleV331Args = {
|
|
240
|
+
propDisplayName: string;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const localStyleHistoryTitlesV331 = {
|
|
244
|
+
title: ( { elementId }: LocalStyleHistoryTitleV331Args ) => getElementLabel( elementId ),
|
|
245
|
+
subtitle: ( { propDisplayName }: LocalStyleHistorySubtitleV331Args ) =>
|
|
246
|
+
// translators: %s is the name of the style property being edited
|
|
247
|
+
__( `%s edited`, 'elementor' ).replace( '%s', propDisplayName ),
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
function capitalize( str: string ) {
|
|
251
|
+
return str.charAt( 0 ).toUpperCase() + str.slice( 1 );
|
|
252
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { injectIntoLogic } from '@elementor/editor';
|
|
2
|
-
import { PrefetchUserData } from '@elementor/editor-current-user';
|
|
3
2
|
import { __registerPanel as registerPanel } from '@elementor/editor-panels';
|
|
4
3
|
import { blockCommand, isExperimentActive } from '@elementor/editor-v1-adapters';
|
|
5
4
|
|
|
@@ -20,11 +19,6 @@ export function init() {
|
|
|
20
19
|
component: EditingPanelHooks,
|
|
21
20
|
} );
|
|
22
21
|
|
|
23
|
-
injectIntoLogic( {
|
|
24
|
-
id: 'current-user-data',
|
|
25
|
-
component: PrefetchUserData,
|
|
26
|
-
} );
|
|
27
|
-
|
|
28
22
|
// TODO: Move it from here once we have dynamic package.
|
|
29
23
|
initDynamics();
|
|
30
24
|
|