@elementor/editor-editing-panel 1.4.0 → 1.5.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.
@@ -1,75 +0,0 @@
1
- import { useCallback, useMemo } from 'react';
2
- import { getElementStyles, getVariantByMeta, updateStyle } from '@elementor/editor-elements';
3
- import { type PropKey } from '@elementor/editor-props';
4
-
5
- import { useElement } from '../contexts/element-context';
6
- import { useStyle } from '../contexts/style-context';
7
- import { usePropValueHistory } from './use-prop-value-history';
8
-
9
- export const useStylePropsHistory = ( props: PropKey[] ) => {
10
- const { element } = useElement();
11
- const { id: styleDefID, meta } = useStyle();
12
- const { getPropValue, setPropValue, removeProp } = usePropValueHistory();
13
-
14
- const styleDef = styleDefID ? getElementStyles( element.id )?.[ styleDefID ] : null;
15
- const styleVariant = styleDef ? getVariantByMeta( styleDef, meta ) : null;
16
- const styleVariantPath = `${ styleDefID }-${ styleVariant?.meta.breakpoint }-${ styleVariant?.meta.state }`;
17
-
18
- const saveStylePropsHistory = useCallback( () => {
19
- props.forEach( ( propKey ) => {
20
- const propValue = styleVariant?.props[ propKey ];
21
-
22
- if ( propValue ) {
23
- const propPath = `${ styleVariantPath }-${ propKey }`;
24
- setPropValue( propPath, propValue );
25
- }
26
- } );
27
- }, [ props, setPropValue, styleVariant?.props, styleVariantPath ] );
28
-
29
- const updateStylePropsFromHistory = useCallback( () => {
30
- const propValuesFromHistory = props.reduce( ( allProps, currentPropKey ) => {
31
- const propPath = `${ styleVariantPath }-${ currentPropKey }`;
32
- const propHistory = getPropValue( propPath );
33
-
34
- if ( propHistory ) {
35
- removeProp( propPath );
36
- return { ...allProps, [ currentPropKey ]: propHistory };
37
- }
38
-
39
- return allProps;
40
- }, {} );
41
-
42
- if ( Object.keys( propValuesFromHistory ).length ) {
43
- updateStyle( {
44
- elementID: element.id,
45
- styleDefID,
46
- meta,
47
- props: propValuesFromHistory,
48
- bind: 'classes',
49
- } );
50
- }
51
- }, [ element.id, getPropValue, meta, props, removeProp, styleDefID, styleVariantPath ] );
52
-
53
- const clearCurrentStyleProps = useCallback( () => {
54
- const resetValues = props.reduce(
55
- ( allProps, currentPropKey ) => ( {
56
- ...allProps,
57
- [ currentPropKey ]: undefined,
58
- } ),
59
- {}
60
- );
61
-
62
- updateStyle( {
63
- elementID: element.id,
64
- styleDefID,
65
- meta,
66
- props: resetValues,
67
- bind: 'classes',
68
- } );
69
- }, [ element.id, meta, props, styleDefID ] );
70
-
71
- return useMemo(
72
- () => ( { saveStylePropsHistory, updateStylePropsFromHistory, clearCurrentStyleProps } ),
73
- [ saveStylePropsHistory, updateStylePropsFromHistory, clearCurrentStyleProps ]
74
- );
75
- };