@elementor/editor-editing-panel 1.2.0 → 1.4.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/index.js +852 -615
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +790 -544
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +13 -11
  7. package/src/components/conditional-tooltip-wrapper.tsx +52 -0
  8. package/src/components/css-class-selector.tsx +59 -19
  9. package/src/components/multi-combobox/types.ts +1 -0
  10. package/src/components/style-sections/border-section/border-radius-field.tsx +4 -4
  11. package/src/components/style-sections/border-section/border-width-field.tsx +4 -4
  12. package/src/components/style-sections/layout-section/align-items-field.tsx +40 -60
  13. package/src/components/style-sections/layout-section/align-self-child-field.tsx +72 -0
  14. package/src/components/style-sections/layout-section/flex-direction-field.tsx +2 -2
  15. package/src/components/style-sections/layout-section/flex-order-field.tsx +14 -8
  16. package/src/components/style-sections/layout-section/flex-size-field.tsx +164 -0
  17. package/src/components/style-sections/layout-section/gap-control-field.tsx +18 -0
  18. package/src/components/style-sections/layout-section/justify-content-field.tsx +51 -78
  19. package/src/components/style-sections/layout-section/layout-section.tsx +9 -2
  20. package/src/components/style-sections/layout-section/utils/rotated-icon.tsx +52 -0
  21. package/src/components/style-sections/layout-section/wrap-field.tsx +1 -1
  22. package/src/components/style-sections/position-section/position-section.tsx +3 -3
  23. package/src/components/style-sections/typography-section/line-height-field.tsx +21 -0
  24. package/src/components/style-sections/typography-section/text-style-field.tsx +31 -8
  25. package/src/components/style-sections/typography-section/typography-section.tsx +3 -1
  26. package/src/components/style-tab.tsx +2 -11
  27. package/src/contexts/style-context.tsx +2 -2
  28. package/src/controls-registry/controls-registry.tsx +4 -0
  29. package/src/dynamics/components/dynamic-selection-control.tsx +8 -5
  30. package/src/dynamics/components/dynamic-selection.tsx +10 -8
  31. package/src/dynamics/dynamic-control.tsx +9 -11
  32. package/src/dynamics/utils.ts +20 -3
  33. package/src/hooks/use-style-prop-history.ts +1 -1
  34. package/src/hooks/use-styles-field.ts +2 -0
@@ -27,15 +27,17 @@ import { type ControlType, getControlByType } from '../../controls-registry/cont
27
27
  import { usePropValueHistory } from '../../hooks/use-prop-value-history';
28
28
  import { DynamicControl } from '../dynamic-control';
29
29
  import { useDynamicTag } from '../hooks/use-dynamic-tag';
30
- import { type DynamicPropValue, type DynamicTag } from '../types';
30
+ import { type DynamicTag } from '../types';
31
+ import { dynamicPropTypeUtil } from '../utils';
31
32
  import { DynamicSelection } from './dynamic-selection';
32
33
 
33
34
  const SIZE = 'tiny';
34
35
 
35
36
  export const DynamicSelectionControl = () => {
36
- const { bind, value, setValue } = useBoundProp< DynamicPropValue | null >();
37
+ const { setValue: setAnyValue } = useBoundProp();
38
+ const { bind, value } = useBoundProp( dynamicPropTypeUtil );
37
39
  const { getPropValue: getPropValueFromHistory } = usePropValueHistory();
38
- const { name: tagName = '' } = value?.value || {};
40
+ const { name: tagName = '' } = value;
39
41
 
40
42
  const selectionPopoverId = useId();
41
43
  const selectionPopoverState = usePopupState( { variant: 'popover', popupId: selectionPopoverId } );
@@ -43,8 +45,9 @@ export const DynamicSelectionControl = () => {
43
45
  const dynamicTag = useDynamicTag( bind, tagName );
44
46
 
45
47
  const removeDynamicTag = () => {
46
- const propValue = getPropValueFromHistory< DynamicPropValue >( bind );
47
- setValue( propValue ?? null );
48
+ const propValue = getPropValueFromHistory( bind );
49
+
50
+ setAnyValue( propValue ?? null );
48
51
  };
49
52
 
50
53
  if ( ! dynamicTag ) {
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { Fragment, useState } from 'react';
3
3
  import { useBoundProp } from '@elementor/editor-controls';
4
- import { type PropKey, type PropValue } from '@elementor/editor-props';
4
+ import { type PropKey } from '@elementor/editor-props';
5
5
  import { PhotoIcon, SearchIcon } from '@elementor/icons';
6
6
  import {
7
7
  Box,
@@ -20,8 +20,7 @@ import { __ } from '@wordpress/i18n';
20
20
  import { usePropValueHistory } from '../../hooks/use-prop-value-history';
21
21
  import { usePropDynamicTags } from '../hooks/use-prop-dynamic-tags';
22
22
  import { getAtomicDynamicTags } from '../sync/get-atomic-dynamic-tags';
23
- import { type DynamicPropValue } from '../types';
24
- import { isDynamicPropValue } from '../utils';
23
+ import { dynamicPropTypeUtil } from '../utils';
25
24
 
26
25
  type Option = {
27
26
  label: string;
@@ -39,10 +38,13 @@ export type DynamicSelectionProps = {
39
38
  export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
40
39
  const [ searchValue, setSearchValue ] = useState( '' );
41
40
  const { groups: dynamicGroups } = getAtomicDynamicTags() || {};
42
- const { bind, value: currentValue, setValue } = useBoundProp< DynamicPropValue | PropValue >();
41
+
42
+ const { value: anyValue } = useBoundProp();
43
+ const { bind, value: dynamicvalue, setValue } = useBoundProp( dynamicPropTypeUtil );
44
+
43
45
  const { setPropValue: updatePropValueHistory } = usePropValueHistory();
44
46
 
45
- const isCurrentValueDynamic = isDynamicPropValue( currentValue );
47
+ const isCurrentValueDynamic = !! dynamicvalue;
46
48
 
47
49
  const options = useFilteredOptions( bind, searchValue );
48
50
 
@@ -52,10 +54,10 @@ export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
52
54
 
53
55
  const handleSetDynamicTag = ( value: string ) => {
54
56
  if ( ! isCurrentValueDynamic ) {
55
- updatePropValueHistory( bind, currentValue );
57
+ updatePropValueHistory( bind, anyValue );
56
58
  }
57
59
 
58
- setValue( { $$type: 'dynamic', value: { name: value, settings: {} } } );
60
+ setValue( { name: value, settings: {} } );
59
61
 
60
62
  onSelect?.();
61
63
  };
@@ -88,7 +90,7 @@ export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
88
90
  { dynamicGroups?.[ category ]?.title || category }
89
91
  </ListSubheader>
90
92
  { items.map( ( { value, label: tagLabel } ) => {
91
- const isSelected = isCurrentValueDynamic && value === currentValue?.value?.name;
93
+ const isSelected = isCurrentValueDynamic && value === dynamicvalue?.name;
92
94
 
93
95
  return (
94
96
  <MenuItem
@@ -1,17 +1,17 @@
1
1
  import * as React from 'react';
2
2
  import { BoundPropProvider, useBoundProp } from '@elementor/editor-controls';
3
- import { type PropKey, type PropValue } from '@elementor/editor-props';
3
+ import { isTransformable, type PropKey, type PropValue } from '@elementor/editor-props';
4
4
 
5
5
  import { useDynamicTag } from './hooks/use-dynamic-tag';
6
- import { type DynamicPropValue } from './types';
6
+ import { dynamicPropTypeUtil } from './utils';
7
7
 
8
8
  export type DynamicControlProps = React.PropsWithChildren< {
9
9
  bind: PropKey;
10
10
  } >;
11
11
 
12
12
  export const DynamicControl = ( { bind, children }: DynamicControlProps ) => {
13
- const { value, setValue, bind: propName } = useBoundProp< DynamicPropValue >();
14
- const { name = '', settings } = value?.value ?? {};
13
+ const { value, setValue, bind: propName } = useBoundProp( dynamicPropTypeUtil );
14
+ const { name = '', settings } = value ?? {};
15
15
 
16
16
  const dynamicTag = useDynamicTag( propName, name );
17
17
 
@@ -24,13 +24,11 @@ export const DynamicControl = ( { bind, children }: DynamicControlProps ) => {
24
24
 
25
25
  const setDynamicValue = ( newValue: PropValue ) => {
26
26
  setValue( {
27
- $$type: 'dynamic',
28
- value: {
29
- name,
30
- settings: {
31
- ...settings,
32
- [ bind ]: newValue,
33
- },
27
+ name,
28
+ settings: {
29
+ ...settings,
30
+ // The value inside the dynamic is not a transformable value, so we need to store the whole object.
31
+ [ bind ]: isTransformable( newValue ) ? newValue.value : newValue,
34
32
  },
35
33
  } );
36
34
  };
@@ -1,8 +1,15 @@
1
- import { isTransformable, type PropType, type PropValue, type TransformablePropType } from '@elementor/editor-props';
1
+ import {
2
+ createPropUtils,
3
+ isTransformable,
4
+ type PropType,
5
+ type PropValue,
6
+ type TransformablePropType,
7
+ } from '@elementor/editor-props';
8
+ import { z } from '@elementor/schema';
2
9
 
3
- import { type DynamicPropType, type DynamicPropValue } from './types';
10
+ import { type DynamicPropType } from './types';
4
11
 
5
- const DYNAMIC_PROP_TYPE_KEY = 'dynamic';
12
+ export const DYNAMIC_PROP_TYPE_KEY = 'dynamic';
6
13
 
7
14
  export const isDynamicPropType = ( prop: TransformablePropType ): prop is DynamicPropType =>
8
15
  prop.key === DYNAMIC_PROP_TYPE_KEY;
@@ -20,3 +27,13 @@ export const isDynamicPropValue = ( prop: PropValue ): prop is DynamicPropValue
20
27
  export const supportsDynamic = ( propType: PropType ): boolean => {
21
28
  return !! getDynamicPropType( propType );
22
29
  };
30
+
31
+ export const dynamicPropTypeUtil = createPropUtils(
32
+ DYNAMIC_PROP_TYPE_KEY,
33
+ z.strictObject( {
34
+ name: z.string(),
35
+ settings: z.record( z.any() ).optional(),
36
+ } )
37
+ );
38
+
39
+ export type DynamicPropValue = z.infer< typeof dynamicPropTypeUtil.schema >;
@@ -11,7 +11,7 @@ export const useStylePropsHistory = ( props: PropKey[] ) => {
11
11
  const { id: styleDefID, meta } = useStyle();
12
12
  const { getPropValue, setPropValue, removeProp } = usePropValueHistory();
13
13
 
14
- const styleDef = getElementStyles( element.id )?.[ styleDefID ];
14
+ const styleDef = styleDefID ? getElementStyles( element.id )?.[ styleDefID ] : null;
15
15
  const styleVariant = styleDef ? getVariantByMeta( styleDef, meta ) : null;
16
16
  const styleVariantPath = `${ styleDefID }-${ styleVariant?.meta.breakpoint }-${ styleVariant?.meta.state }`;
17
17
 
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import { updateStyle, useElementStyleProp } from '@elementor/editor-elements';
3
3
  import type { PropKey, PropValue } from '@elementor/editor-props';
4
+ import { __ } from '@wordpress/i18n';
4
5
 
5
6
  import { useClassesProp } from '../contexts/classes-prop-context';
6
7
  import { useElement } from '../contexts/element-context';
@@ -33,6 +34,7 @@ export const useStylesField = < T extends PropValue >(
33
34
  props: { [ propName ]: newValue },
34
35
  meta,
35
36
  bind: classesProp,
37
+ label: __( 'local', 'elementor' ),
36
38
  } );
37
39
  };
38
40