@elementor/editor-editing-panel 4.1.0-811 → 4.1.0-813

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-editing-panel",
3
- "version": "4.1.0-811",
3
+ "version": "4.1.0-813",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,28 +39,28 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.1.0-811",
43
- "@elementor/editor-canvas": "4.1.0-811",
44
- "@elementor/editor-controls": "4.1.0-811",
45
- "@elementor/editor-documents": "4.1.0-811",
46
- "@elementor/editor-elements": "4.1.0-811",
47
- "@elementor/editor-interactions": "4.1.0-811",
48
- "@elementor/editor-panels": "4.1.0-811",
49
- "@elementor/editor-props": "4.1.0-811",
50
- "@elementor/editor-responsive": "4.1.0-811",
51
- "@elementor/editor-styles": "4.1.0-811",
52
- "@elementor/editor-styles-repository": "4.1.0-811",
53
- "@elementor/editor-ui": "4.1.0-811",
54
- "@elementor/editor-v1-adapters": "4.1.0-811",
42
+ "@elementor/editor": "4.1.0-813",
43
+ "@elementor/editor-canvas": "4.1.0-813",
44
+ "@elementor/editor-controls": "4.1.0-813",
45
+ "@elementor/editor-documents": "4.1.0-813",
46
+ "@elementor/editor-elements": "4.1.0-813",
47
+ "@elementor/editor-interactions": "4.1.0-813",
48
+ "@elementor/editor-panels": "4.1.0-813",
49
+ "@elementor/editor-props": "4.1.0-813",
50
+ "@elementor/editor-responsive": "4.1.0-813",
51
+ "@elementor/editor-styles": "4.1.0-813",
52
+ "@elementor/editor-styles-repository": "4.1.0-813",
53
+ "@elementor/editor-ui": "4.1.0-813",
54
+ "@elementor/editor-v1-adapters": "4.1.0-813",
55
55
  "@elementor/icons": "^1.68.0",
56
- "@elementor/editor-variables": "4.1.0-811",
57
- "@elementor/locations": "4.1.0-811",
58
- "@elementor/menus": "4.1.0-811",
59
- "@elementor/schema": "4.1.0-811",
60
- "@elementor/session": "4.1.0-811",
56
+ "@elementor/editor-variables": "4.1.0-813",
57
+ "@elementor/locations": "4.1.0-813",
58
+ "@elementor/menus": "4.1.0-813",
59
+ "@elementor/schema": "4.1.0-813",
60
+ "@elementor/session": "4.1.0-813",
61
61
  "@elementor/ui": "1.37.5",
62
- "@elementor/utils": "4.1.0-811",
63
- "@elementor/wp-media": "4.1.0-811",
62
+ "@elementor/utils": "4.1.0-813",
63
+ "@elementor/wp-media": "4.1.0-813",
64
64
  "@wordpress/i18n": "^5.13.0"
65
65
  },
66
66
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
- import { createContext, type PropsWithChildren, useContext } from 'react';
2
+ import { createContext, type PropsWithChildren, useContext, useMemo } from 'react';
3
3
  import { getWidgetsCache } from '@elementor/editor-elements';
4
- import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
4
+ import { classesPropTypeUtil, type ClassesPropValue, type PropValue } from '@elementor/editor-props';
5
5
  import { getBreakpointsTree } from '@elementor/editor-responsive';
6
6
  import { getStylesSchema } from '@elementor/editor-styles';
7
7
  import { stylesRepository } from '@elementor/editor-styles-repository';
@@ -64,6 +64,20 @@ export function useStylesInheritanceChain( path: string[] ): SnapshotPropValue[]
64
64
  return context.getInheritanceChain( snapshot, path, topLevelPropType );
65
65
  }
66
66
 
67
+ const EMPTY_INHERITED_VALUES: Record< string, PropValue > = {};
68
+
69
+ export function useInheritedValues( propKeys: string[] ): Record< string, PropValue > {
70
+ const snapshot = useStylesInheritanceSnapshot();
71
+
72
+ return useMemo( () => {
73
+ if ( ! snapshot || propKeys.length === 0 ) {
74
+ return EMPTY_INHERITED_VALUES;
75
+ }
76
+
77
+ return Object.fromEntries( propKeys.map( ( key ) => [ key, snapshot[ key ]?.[ 0 ]?.value ?? null ] ) );
78
+ }, [ snapshot, propKeys ] );
79
+ }
80
+
67
81
  const useAppliedStyles = () => {
68
82
  const currentClassesProp = useClassesProp();
69
83
  const baseStyles = useBaseStyles();
@@ -1,22 +1,96 @@
1
+ import { type FC, type ReactNode, useEffect, useRef } from 'react';
1
2
  import { useBoundProp } from '@elementor/editor-controls';
2
- import { isDependency, isDependencyMet, type PropKey, type PropType } from '@elementor/editor-props';
3
+ import { isDependency, isDependencyMet, type PropKey, type PropType, type PropValue } from '@elementor/editor-props';
3
4
 
5
+ import { useInheritedValues } from '../contexts/styles-inheritance-context';
4
6
  import { useStylesFields } from '../hooks/use-styles-fields';
5
7
 
6
- export const ConditionalField: React.FC< {
7
- children: React.ReactNode;
8
- } > = ( { children } ) => {
9
- const { propType } = useBoundProp();
8
+ type DepValues = Record< string, PropValue > | null;
9
+
10
+ export const ConditionalField: FC< { children: ReactNode } > = ( { children } ) => {
11
+ const { propType, value, resetValue } = useBoundProp();
10
12
 
11
13
  const depList = getDependencies( propType );
12
14
 
13
- const { values: depValues } = useStylesFields( depList );
15
+ const { values: depValues, setValues: setDepValues } = useStylesFields( depList );
16
+ const inheritedValues = useInheritedValues( depList );
17
+
18
+ const resolvedValues = resolveWithInherited( depValues, inheritedValues );
19
+ const isHidden = ! isDependencyMet( propType?.dependencies, resolvedValues ).isMet;
14
20
 
15
- const isHidden = ! isDependencyMet( propType?.dependencies, depValues ).isMet;
21
+ useSyncDepsWithInherited( { isHidden, depValues, value, inheritedValues, setDepValues, resetValue } );
16
22
 
17
23
  return isHidden ? null : children;
18
24
  };
19
25
 
26
+ function wasDepsCleared( prevDepValues: DepValues, depValues: DepValues ): boolean {
27
+ if ( ! prevDepValues ) {
28
+ return false;
29
+ }
30
+
31
+ return Object.keys( prevDepValues ).some(
32
+ ( key ) => prevDepValues[ key ] && ( ! depValues || ! depValues[ key ] )
33
+ );
34
+ }
35
+
36
+ function useSyncDepsWithInherited( {
37
+ isHidden,
38
+ depValues,
39
+ value,
40
+ inheritedValues,
41
+ setDepValues,
42
+ resetValue,
43
+ }: {
44
+ isHidden: boolean;
45
+ depValues: DepValues;
46
+ value: PropValue;
47
+ inheritedValues: Record< string, PropValue >;
48
+ setDepValues: ( props: Record< string, PropValue >, options: { history: { propDisplayName: string } } ) => void;
49
+ resetValue: () => void;
50
+ } ) {
51
+ const syncRef = useRef( { hasSynced: false, prevDepValues: depValues } );
52
+
53
+ useEffect( () => {
54
+ const { hasSynced, prevDepValues } = syncRef.current;
55
+
56
+ if ( hasSynced && value && wasDepsCleared( prevDepValues, depValues ) ) {
57
+ resetValue();
58
+ }
59
+
60
+ if ( isHidden || ! value || ! depValues ) {
61
+ syncRef.current = { hasSynced: false, prevDepValues: depValues };
62
+ return;
63
+ }
64
+
65
+ if ( hasSynced ) {
66
+ syncRef.current.prevDepValues = depValues;
67
+ return;
68
+ }
69
+
70
+ syncRef.current = { hasSynced: true, prevDepValues: depValues };
71
+
72
+ Object.entries( depValues ).forEach( ( [ key, depValue ] ) => {
73
+ const inherited = inheritedValues[ key ];
74
+
75
+ if ( ! depValue && inherited ) {
76
+ setDepValues( { [ key ]: inherited }, { history: { propDisplayName: key } } );
77
+ }
78
+ } );
79
+ }, [ isHidden, depValues, value, inheritedValues, setDepValues, resetValue ] );
80
+ }
81
+
82
+ function resolveWithInherited( localValues: DepValues, inheritedValues: Record< string, PropValue > ): DepValues {
83
+ if ( ! localValues ) {
84
+ const hasInherited = Object.keys( inheritedValues ).length > 0;
85
+
86
+ return hasInherited ? { ...inheritedValues } : null;
87
+ }
88
+
89
+ return Object.fromEntries(
90
+ Object.entries( localValues ).map( ( [ key, val ] ) => [ key, val ?? inheritedValues[ key ] ?? null ] )
91
+ );
92
+ }
93
+
20
94
  export function getDependencies( propType?: PropType ): PropKey[] {
21
95
  if ( ! propType?.dependencies?.terms.length ) {
22
96
  return [];