@elementor/editor-editing-panel 0.18.0 → 1.0.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 (115) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/index.d.mts +8 -24
  3. package/dist/index.d.ts +8 -24
  4. package/dist/index.js +1452 -1122
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1436 -1099
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +15 -14
  9. package/src/components/accordion-section.tsx +3 -2
  10. package/src/components/add-or-remove-content.tsx +42 -0
  11. package/src/components/collapsible-field.tsx +34 -0
  12. package/src/components/editing-panel-error-fallback.tsx +12 -0
  13. package/src/components/editing-panel.tsx +27 -19
  14. package/src/components/settings-tab.tsx +12 -11
  15. package/src/components/style-sections/background-section/background-color-field.tsx +21 -0
  16. package/src/components/style-sections/background-section/background-section.tsx +15 -0
  17. package/src/components/style-sections/border-section/border-color-field.tsx +21 -0
  18. package/src/components/style-sections/border-section/border-field.tsx +47 -0
  19. package/src/components/style-sections/border-section/border-radius-field.tsx +48 -0
  20. package/src/components/style-sections/border-section/border-section.tsx +16 -0
  21. package/src/components/style-sections/border-section/border-style-field.tsx +32 -0
  22. package/src/components/style-sections/border-section/border-width-field.tsx +42 -0
  23. package/src/components/style-sections/effects-section/effects-section.tsx +5 -5
  24. package/src/components/style-sections/position-section/dimensions-field.tsx +46 -0
  25. package/src/components/style-sections/position-section/position-field.tsx +28 -0
  26. package/src/components/style-sections/position-section/position-section.tsx +15 -2
  27. package/src/components/style-sections/position-section/z-index-field.tsx +21 -0
  28. package/src/components/style-sections/size-section/overflow-field.tsx +45 -0
  29. package/src/components/style-sections/size-section/size-section.tsx +55 -0
  30. package/src/components/style-sections/spacing-section/spacing-section.tsx +6 -6
  31. package/src/components/style-sections/typography-section/font-size-field.tsx +21 -0
  32. package/src/components/style-sections/typography-section/{font-weight-control.tsx → font-weight-field.tsx} +7 -6
  33. package/src/components/style-sections/typography-section/letter-spacing-field.tsx +21 -0
  34. package/src/components/style-sections/typography-section/{text-alignment-control.tsx → text-alignment-field.tsx} +8 -8
  35. package/src/components/style-sections/typography-section/text-color-field.tsx +21 -0
  36. package/src/components/style-sections/typography-section/{text-direction-control.tsx → text-direction-field.tsx} +8 -8
  37. package/src/components/style-sections/typography-section/text-stroke-field.tsx +16 -0
  38. package/src/components/style-sections/typography-section/{text-style-control.tsx → text-style-field.tsx} +5 -5
  39. package/src/components/style-sections/typography-section/{transform-control.tsx → transform-field.tsx} +8 -7
  40. package/src/components/style-sections/typography-section/typography-section.tsx +20 -18
  41. package/src/components/style-sections/typography-section/word-spacing-field.tsx +21 -0
  42. package/src/components/style-tab.tsx +44 -25
  43. package/src/contexts/classes-prop-context.tsx +24 -0
  44. package/src/contexts/element-context.tsx +6 -10
  45. package/src/contexts/style-context.tsx +8 -22
  46. package/src/control-replacement.tsx +3 -0
  47. package/src/controls/bound-prop-context.tsx +30 -0
  48. package/src/controls/components/control-toggle-button-group.tsx +15 -6
  49. package/src/controls/components/repeater.tsx +1 -1
  50. package/src/controls/components/text-field-inner-selection.tsx +20 -24
  51. package/src/controls/control-actions/control-actions-context.tsx +27 -0
  52. package/src/controls/control-actions/control-actions-menu.ts +6 -7
  53. package/src/controls/control-actions/control-actions.tsx +14 -26
  54. package/src/{components/style-sections/effects-section/box-shadow-repeater.tsx → controls/controls/box-shadow-repeater-control.tsx} +51 -65
  55. package/src/controls/controls/color-control.tsx +25 -0
  56. package/src/controls/controls/equal-unequal-sizes-control.tsx +196 -0
  57. package/src/controls/{control-types → controls}/image-control.tsx +15 -23
  58. package/src/controls/{control-types → controls}/image-media-control.tsx +5 -14
  59. package/src/{components/style-sections/spacing-section → controls/controls}/linked-dimensions-control.tsx +10 -26
  60. package/src/controls/{control-types → controls}/number-control.tsx +2 -2
  61. package/src/controls/{control-types → controls}/select-control.tsx +4 -4
  62. package/src/controls/{control-types → controls}/size-control.tsx +8 -8
  63. package/src/controls/controls/stroke-control.tsx +105 -0
  64. package/src/controls/{control-types → controls}/text-area-control.tsx +3 -3
  65. package/src/controls/{control-types → controls}/text-control.tsx +3 -3
  66. package/src/controls/{control-types → controls}/toggle-control.tsx +4 -4
  67. package/src/controls/create-control-replacement.tsx +53 -0
  68. package/src/controls/create-control.tsx +12 -3
  69. package/src/controls/index.ts +24 -0
  70. package/src/controls-actions.ts +8 -0
  71. package/src/{controls/components → controls-registry}/control-type-container.tsx +1 -1
  72. package/src/{controls → controls-registry}/controls-registry.tsx +1 -6
  73. package/src/controls-registry/settings-field.tsx +35 -0
  74. package/src/controls-registry/styles-field.tsx +19 -0
  75. package/src/dynamics/components/dynamic-selection-control.tsx +11 -11
  76. package/src/dynamics/components/dynamic-selection.tsx +6 -6
  77. package/src/dynamics/dynamic-control.tsx +6 -5
  78. package/src/dynamics/hooks/use-dynamic-tag.ts +2 -2
  79. package/src/dynamics/hooks/use-prop-dynamic-action.tsx +7 -7
  80. package/src/dynamics/hooks/use-prop-dynamic-tags.ts +3 -3
  81. package/src/dynamics/hooks/use-prop-value-history.ts +3 -3
  82. package/src/dynamics/init.ts +2 -4
  83. package/src/dynamics/types.ts +2 -1
  84. package/src/dynamics/utils.ts +1 -2
  85. package/src/hooks/use-styles-field.ts +30 -0
  86. package/src/index.ts +3 -4
  87. package/src/sync/should-use-v2-panel.ts +1 -2
  88. package/src/sync/types.ts +3 -2
  89. package/src/components/style-sections/position-section/z-index-control.tsx +0 -20
  90. package/src/components/style-sections/size-section.tsx +0 -49
  91. package/src/components/style-sections/typography-section/font-size-control.tsx +0 -20
  92. package/src/components/style-sections/typography-section/letter-spacing-control.tsx +0 -20
  93. package/src/components/style-sections/typography-section/text-color-control.tsx +0 -20
  94. package/src/components/style-sections/typography-section/word-spacing-control.tsx +0 -20
  95. package/src/controls/control-context.tsx +0 -22
  96. package/src/controls/control-replacement.ts +0 -34
  97. package/src/controls/control-types/color-control.tsx +0 -27
  98. package/src/controls/hooks/use-style-control.ts +0 -29
  99. package/src/controls/settings-control.tsx +0 -37
  100. package/src/controls/style-control.tsx +0 -20
  101. package/src/hooks/use-element-style-prop.ts +0 -45
  102. package/src/hooks/use-element-styles.ts +0 -13
  103. package/src/hooks/use-element-type.ts +0 -33
  104. package/src/hooks/use-selected-elements.ts +0 -9
  105. package/src/hooks/use-widget-settings.ts +0 -16
  106. package/src/props/is-transformable.ts +0 -14
  107. package/src/sync/get-container.ts +0 -8
  108. package/src/sync/get-element-styles.ts +0 -9
  109. package/src/sync/get-selected-elements.ts +0 -21
  110. package/src/sync/get-widgets-cache.ts +0 -7
  111. package/src/sync/update-settings.ts +0 -14
  112. package/src/sync/update-style.ts +0 -24
  113. package/src/types.ts +0 -89
  114. package/src/{controls → controls-registry}/control.tsx +0 -0
  115. package/src/{controls/control-actions/actions/popover-action.tsx → popover-action.tsx} +1 -1
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentProps, ComponentType } from 'react';
3
- import { useControlReplacement } from './control-replacement';
3
+ import { useControlReplacement } from './create-control-replacement';
4
+ import { ErrorBoundary } from '@elementor/ui';
4
5
 
5
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
7
  type AnyComponentType = ComponentType< any >;
@@ -23,9 +24,17 @@ export function createControl< T extends AnyComponentType >(
23
24
  const ControlReplacement = useControlReplacement();
24
25
 
25
26
  if ( ControlReplacement && supportsReplacements ) {
26
- return <ControlReplacement { ...props } />;
27
+ return (
28
+ <ErrorBoundary fallback={ null }>
29
+ <ControlReplacement { ...props } />
30
+ </ErrorBoundary>
31
+ );
27
32
  }
28
33
 
29
- return <Component { ...props } />;
34
+ return (
35
+ <ErrorBoundary fallback={ null }>
36
+ <Component { ...props } />
37
+ </ErrorBoundary>
38
+ );
30
39
  } ) as ControlComponent< T >;
31
40
  }
@@ -0,0 +1,24 @@
1
+ // control types
2
+ export { ImageControl } from './controls/image-control';
3
+ export { TextControl } from './controls/text-control';
4
+ export { TextAreaControl } from './controls/text-area-control';
5
+ export { SizeControl } from './controls/size-control';
6
+ export { StrokeControl } from './controls/stroke-control';
7
+ export { BoxShadowRepeaterControl } from './controls/box-shadow-repeater-control';
8
+ export { SelectControl } from './controls/select-control';
9
+ export { ColorControl } from './controls/color-control';
10
+ export { ToggleControl } from './controls/toggle-control';
11
+ export { NumberControl } from './controls/number-control';
12
+
13
+ // types
14
+ export type { ControlComponent } from './create-control';
15
+ export type { ToggleButtonGroupItem } from './components/control-toggle-button-group';
16
+ export type { SizeControlValue } from './controls/size-control';
17
+
18
+ // Providers
19
+ export { ControlActionsProvider } from './control-actions/control-actions-context';
20
+ export { createControlReplacement, ControlReplacementProvider } from './create-control-replacement';
21
+ export { useBoundProp, BoundPropProvider } from './bound-prop-context';
22
+
23
+ // utils
24
+ export { createControlActionsMenu } from './control-actions/control-actions-menu';
@@ -0,0 +1,8 @@
1
+ import { createControlActionsMenu } from './controls';
2
+ import PopoverAction from './popover-action';
3
+
4
+ export const { useMenuItems, registerPopoverAction } = createControlActionsMenu( {
5
+ components: {
6
+ PopoverAction,
7
+ },
8
+ } );
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { styled, Box, BoxProps } from '@elementor/ui';
3
- import { ControlLayout, ControlType, getLayoutByType } from '../controls-registry';
3
+ import { ControlLayout, ControlType, getLayoutByType } from './controls-registry';
4
4
 
5
5
  export const ControlTypeContainer = ( {
6
6
  controlType,
@@ -1,9 +1,4 @@
1
- import { ImageControl } from './control-types/image-control';
2
- import { TextControl } from './control-types/text-control';
3
- import { TextAreaControl } from './control-types/text-area-control';
4
- import { SizeControl } from './control-types/size-control';
5
- import { SelectControl } from './control-types/select-control';
6
- import { ControlComponent } from './create-control';
1
+ import { ControlComponent, ImageControl, SelectControl, SizeControl, TextAreaControl, TextControl } from '../controls';
7
2
 
8
3
  export type ControlLayout = 'full' | 'two-columns';
9
4
 
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ import { PropKey, PropValue } from '@elementor/editor-props';
3
+ import { useElementSetting, updateSettings } from '@elementor/editor-elements';
4
+ import { useElement } from '../contexts/element-context';
5
+ import { BoundPropProvider } from '../controls';
6
+
7
+ type Props = {
8
+ bind: PropKey;
9
+ children: React.ReactNode;
10
+ };
11
+
12
+ const SettingsField = ( { bind, children }: Props ) => {
13
+ const { element, elementType } = useElement();
14
+
15
+ const defaultValue = elementType.propsSchema[ bind ]?.default;
16
+ const settingsValue = useElementSetting( { id: element.id, bind } );
17
+ const value = settingsValue ?? defaultValue ?? null;
18
+
19
+ const setValue = ( newValue: PropValue ) => {
20
+ updateSettings( {
21
+ id: element.id,
22
+ props: {
23
+ [ bind ]: newValue,
24
+ },
25
+ } );
26
+ };
27
+
28
+ return (
29
+ <BoundPropProvider setValue={ setValue } value={ value } bind={ bind }>
30
+ { children }
31
+ </BoundPropProvider>
32
+ );
33
+ };
34
+
35
+ export { SettingsField };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { PropKey } from '@elementor/editor-props';
3
+ import { useStylesField } from '../hooks/use-styles-field';
4
+ import { BoundPropProvider } from '../controls';
5
+
6
+ export type StylesFieldProps = {
7
+ bind: PropKey;
8
+ children: React.ReactNode;
9
+ };
10
+
11
+ export const StylesField = ( { bind, children }: StylesFieldProps ) => {
12
+ const [ value, setValue ] = useStylesField( bind );
13
+
14
+ return (
15
+ <BoundPropProvider setValue={ setValue } value={ value } bind={ bind }>
16
+ { children }
17
+ </BoundPropProvider>
18
+ );
19
+ };
@@ -1,15 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { useId } from 'react';
3
- import { useControl } from '../../controls/control-context';
4
- import { DynamicPropValue, DynamicTag } from '../types';
5
- import { DynamicControl } from '../dynamic-control';
3
+ import { __ } from '@wordpress/i18n';
4
+ import type { Control, ControlsSection } from '@elementor/editor-elements';
6
5
  import { DatabaseIcon, SettingsIcon, XIcon } from '@elementor/icons';
7
- import type { Control, ControlsSection } from '../../types';
8
- import { DynamicSelection } from './dynamic-selection';
9
- import { ControlType, getControlByType } from '../../controls/controls-registry';
10
- import { ControlLabel } from '../../components/control-label';
11
- import { Control as BaseControl } from '../../controls/control';
12
- import { useDynamicTag } from '../hooks/use-dynamic-tag';
13
6
  import {
14
7
  bindPopover,
15
8
  bindTrigger,
@@ -27,13 +20,20 @@ import {
27
20
  Tab,
28
21
  TabPanel,
29
22
  } from '@elementor/ui';
30
- import { __ } from '@wordpress/i18n';
23
+ import { useBoundProp } from '../../controls';
24
+ import { DynamicPropValue, DynamicTag } from '../types';
25
+ import { DynamicControl } from '../dynamic-control';
26
+ import { DynamicSelection } from './dynamic-selection';
27
+ import { ControlLabel } from '../../components/control-label';
28
+ import { Control as BaseControl } from '../../controls-registry/control';
29
+ import { useDynamicTag } from '../hooks/use-dynamic-tag';
31
30
  import { usePropValueHistory } from '../hooks/use-prop-value-history';
31
+ import { ControlType, getControlByType } from '../../controls-registry/controls-registry';
32
32
 
33
33
  const SIZE = 'tiny';
34
34
 
35
35
  export const DynamicSelectionControl = () => {
36
- const { bind, value, setValue } = useControl< DynamicPropValue | null >();
36
+ const { bind, value, setValue } = useBoundProp< DynamicPropValue | null >();
37
37
  const [ propValueFromHistory ] = usePropValueHistory( bind );
38
38
  const { name: tagName = '' } = value?.value || {};
39
39
 
@@ -1,9 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useState, Fragment } from 'react';
3
- import { useControl } from '../../controls/control-context';
4
- import { DynamicPropValue } from '../types';
5
- import { usePropDynamicTags } from '../hooks/use-prop-dynamic-tags';
6
- import { getAtomicDynamicTags } from '../sync/get-atomic-dynamic-tags';
3
+ import { PropKey, PropValue } from '@elementor/editor-props';
7
4
  import { SearchIcon, PhotoIcon } from '@elementor/icons';
8
5
  import {
9
6
  Box,
@@ -18,9 +15,12 @@ import {
18
15
  Typography,
19
16
  } from '@elementor/ui';
20
17
  import { __ } from '@wordpress/i18n';
21
- import { PropKey, PropValue } from '../../types';
18
+ import { useBoundProp } from '../../controls';
19
+ import { usePropDynamicTags } from '../hooks/use-prop-dynamic-tags';
20
+ import { getAtomicDynamicTags } from '../sync/get-atomic-dynamic-tags';
22
21
  import { isDynamicPropValue } from '../utils';
23
22
  import { usePropValueHistory } from '../hooks/use-prop-value-history';
23
+ import { DynamicPropValue } from '../types';
24
24
 
25
25
  type Option = {
26
26
  label: string;
@@ -38,7 +38,7 @@ export type DynamicSelectionProps = {
38
38
  export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
39
39
  const [ searchValue, setSearchValue ] = useState( '' );
40
40
  const { groups: dynamicGroups } = getAtomicDynamicTags() || {};
41
- const { bind, value: currentValue, setValue } = useControl< DynamicPropValue | PropValue >();
41
+ const { bind, value: currentValue, setValue } = useBoundProp< DynamicPropValue | PropValue >();
42
42
  const [ , updatePropValueHistory ] = usePropValueHistory( bind );
43
43
 
44
44
  const isCurrentValueDynamic = isDynamicPropValue( currentValue );
@@ -1,15 +1,16 @@
1
1
  import * as React from 'react';
2
- import { ControlContext, useControl } from '../controls/control-context';
3
- import { PropKey, PropValue } from '../types';
2
+ import { useBoundProp } from '../controls';
3
+ import { PropKey, PropValue } from '@elementor/editor-props';
4
4
  import { useDynamicTag } from './hooks/use-dynamic-tag';
5
5
  import { DynamicPropValue } from './types';
6
+ import { BoundPropProvider } from '../controls/bound-prop-context';
6
7
 
7
8
  export type DynamicControlProps = React.PropsWithChildren< {
8
9
  bind: PropKey;
9
10
  } >;
10
11
 
11
12
  export const DynamicControl = ( { bind, children }: DynamicControlProps ) => {
12
- const { value, setValue, bind: propName } = useControl< DynamicPropValue >();
13
+ const { value, setValue, bind: propName } = useBoundProp< DynamicPropValue >();
13
14
  const { name = '', settings } = value?.value ?? {};
14
15
 
15
16
  const dynamicTag = useDynamicTag( propName, name );
@@ -35,8 +36,8 @@ export const DynamicControl = ( { bind, children }: DynamicControlProps ) => {
35
36
  };
36
37
 
37
38
  return (
38
- <ControlContext.Provider value={ { setValue: setDynamicValue, value: dynamicValue, bind } }>
39
+ <BoundPropProvider setValue={ setDynamicValue } value={ dynamicValue } bind={ bind }>
39
40
  { children }
40
- </ControlContext.Provider>
41
+ </BoundPropProvider>
41
42
  );
42
43
  };
@@ -1,7 +1,7 @@
1
+ import { useMemo } from 'react';
2
+ import { PropKey } from '@elementor/editor-props';
1
3
  import { usePropDynamicTags } from './use-prop-dynamic-tags';
2
4
  import { DynamicTag } from '../types';
3
- import { PropKey } from '../../types';
4
- import { useMemo } from 'react';
5
5
 
6
6
  export const useDynamicTag = ( propName: PropKey, tagName: string ): DynamicTag | null => {
7
7
  const dynamicTags = usePropDynamicTags( propName );
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import { useElementContext } from '../../contexts/element-context';
2
+ import { __ } from '@wordpress/i18n';
3
+ import { DatabaseIcon } from '@elementor/icons';
3
4
  import { supportsDynamic } from '../utils';
4
5
  import { DynamicSelection } from '../components/dynamic-selection';
5
- import { DatabaseIcon } from '@elementor/icons';
6
- import { __ } from '@wordpress/i18n';
7
- import { useControl } from '../../controls/control-context';
8
- import { PopoverActionProps } from '../../controls/control-actions/actions/popover-action';
6
+ import { useBoundProp } from '../../controls';
7
+ import { PopoverActionProps } from '../../popover-action';
8
+ import { useElement } from '../../contexts/element-context';
9
9
 
10
10
  export const usePropDynamicAction = (): PopoverActionProps => {
11
- const { bind } = useControl();
12
- const { elementType } = useElementContext();
11
+ const { bind } = useBoundProp();
12
+ const { elementType } = useElement();
13
13
 
14
14
  const propType = elementType.propsSchema[ bind ];
15
15
  const visible = !! propType && supportsDynamic( propType );
@@ -1,13 +1,13 @@
1
1
  import { useMemo } from 'react';
2
- import { useElementContext } from '../../contexts/element-context';
2
+ import { PropKey } from '@elementor/editor-props';
3
3
  import { getAtomicDynamicTags } from '../sync/get-atomic-dynamic-tags';
4
- import { PropKey } from '../../types';
4
+ import { useElement } from '../../contexts/element-context';
5
5
  import { getDynamicPropType } from '../utils';
6
6
 
7
7
  export const usePropDynamicTags = ( propName: PropKey ) => {
8
8
  let categories: string[] = [];
9
9
 
10
- const { elementType } = useElementContext();
10
+ const { elementType } = useElement();
11
11
 
12
12
  const propType = elementType.propsSchema?.[ propName ];
13
13
 
@@ -1,11 +1,11 @@
1
- import { useElementContext } from '../../contexts/element-context';
2
- import { PropValue } from '../../types';
1
+ import { PropValue } from '@elementor/editor-props';
2
+ import { useElement } from '../../contexts/element-context';
3
3
 
4
4
  export const PROPS_VALUES_HISTORY_KEY = 'elementor/dynamic/non-dynamic-values-history';
5
5
 
6
6
  export const usePropValueHistory = ( path: string ) => {
7
7
  const valuesHistory = getValues();
8
- const { element } = useElementContext();
8
+ const { element } = useElement();
9
9
  const key = `${ element.id }-${ path }`;
10
10
 
11
11
  const value = valuesHistory[ key ] ?? null;
@@ -1,10 +1,8 @@
1
1
  import { DynamicSelectionControl } from './components/dynamic-selection-control';
2
- import { replaceControl } from '../controls/control-replacement';
3
2
  import { isDynamicPropValue } from './utils';
4
3
  import { usePropDynamicAction } from './hooks/use-prop-dynamic-action';
5
- import { controlActionsMenu } from '../controls/control-actions/control-actions-menu';
6
-
7
- const { registerPopoverAction } = controlActionsMenu;
4
+ import { replaceControl } from '../control-replacement';
5
+ import { registerPopoverAction } from '../controls-actions';
8
6
 
9
7
  export const init = () => {
10
8
  replaceControl( {
@@ -1,4 +1,5 @@
1
- import { ControlItem, PropsSchema, TransformablePropType, TransformablePropValue } from '../types';
1
+ import { TransformablePropType, TransformablePropValue } from '@elementor/editor-props';
2
+ import { ControlItem, PropsSchema } from '@elementor/editor-elements';
2
3
 
3
4
  export type ExtendedWindow = Window & {
4
5
  elementor?: {
@@ -1,6 +1,5 @@
1
- import { PropType, PropValue, TransformablePropType } from '../types';
1
+ import { isTransformable, PropType, PropValue, TransformablePropType } from '@elementor/editor-props';
2
2
  import { DynamicPropType, DynamicPropValue } from './types';
3
- import { isTransformable } from '../props/is-transformable';
4
3
 
5
4
  const DYNAMIC_PROP_TYPE_KEY = 'dynamic';
6
5
 
@@ -0,0 +1,30 @@
1
+ import type { PropKey, PropValue } from '@elementor/editor-props';
2
+ import { useElementStyleProp, updateStyle } from '@elementor/editor-elements';
3
+ import { useStyle } from '../contexts/style-context';
4
+ import { useClassesProp } from '../contexts/classes-prop-context';
5
+ import { useElement } from '../contexts/element-context';
6
+
7
+ export const useStylesField = < T extends PropValue >( propName: PropKey ) => {
8
+ const { element } = useElement();
9
+ const { id, meta } = useStyle();
10
+ const classesProp = useClassesProp();
11
+
12
+ const value = useElementStyleProp< T >( {
13
+ elementID: element.id,
14
+ styleDefID: id,
15
+ meta,
16
+ propName,
17
+ } );
18
+
19
+ const setValue = ( newValue: T ) => {
20
+ updateStyle( {
21
+ elementID: element.id,
22
+ styleDefID: id,
23
+ props: { [ propName ]: newValue },
24
+ meta,
25
+ bind: classesProp,
26
+ } );
27
+ };
28
+
29
+ return [ value, setValue ] as const;
30
+ };
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
- export type { PopoverActionProps } from './controls/control-actions/actions/popover-action';
2
- export { replaceControl } from './controls/control-replacement';
3
- export { useControl } from './controls/control-context';
4
- export { controlActionsMenu } from './controls/control-actions/control-actions-menu';
1
+ export type { PopoverActionProps } from './popover-action';
2
+ export { replaceControl } from './control-replacement';
3
+ export { useBoundProp } from './controls';
5
4
 
6
5
  import init from './init';
7
6
 
@@ -1,5 +1,4 @@
1
- import getSelectedElements from './get-selected-elements';
2
- import getWidgetsCache from './get-widgets-cache';
1
+ import { getSelectedElements, getWidgetsCache } from '@elementor/editor-elements';
3
2
 
4
3
  export const shouldUseV2Panel = () => {
5
4
  const selectedElements = getSelectedElements();
package/src/sync/types.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ControlItem, PropsSchema, PropValue } from '../types';
2
- import { StyleDefinition, StyleDefinitionID } from '@elementor/editor-style';
1
+ import { ControlItem, PropsSchema } from '@elementor/editor-elements';
2
+ import { PropValue } from '@elementor/editor-props';
3
+ import { StyleDefinition, StyleDefinitionID } from '@elementor/editor-styles';
3
4
 
4
5
  export type ExtendedWindow = Window & {
5
6
  elementor?: {
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { __ } from '@wordpress/i18n';
3
- import { Grid } from '@elementor/ui';
4
- import { StyleControl } from '../../../controls/style-control';
5
- import { NumberControl } from '../../../controls/control-types/number-control';
6
-
7
- export const ZIndexControl = () => {
8
- return (
9
- <StyleControl bind="z-index">
10
- <Grid container spacing={ 1 } alignItems="center">
11
- <Grid item xs={ 6 }>
12
- <StyleControl.Label>{ __( 'Z-Index', 'elementor' ) }</StyleControl.Label>
13
- </Grid>
14
- <Grid item xs={ 6 }>
15
- <NumberControl />
16
- </Grid>
17
- </Grid>
18
- </StyleControl>
19
- );
20
- };
@@ -1,49 +0,0 @@
1
- import * as React from 'react';
2
- import { AccordionSection } from '../accordion-section';
3
- import { StyleControl, StyleControlProps } from '../../controls/style-control';
4
- import { Grid, Stack } from '@elementor/ui';
5
- import { __ } from '@wordpress/i18n';
6
- import { Control as BaseControl } from '../../controls/control';
7
-
8
- export const SizeSection = () => {
9
- return (
10
- <AccordionSection title={ __( 'Size', 'elementor' ) }>
11
- <Stack gap={ 1.5 }>
12
- <Grid container spacing={ 2 }>
13
- <Control bind="width" label={ __( 'Width', 'elementor' ) } />
14
- <Control bind="height" label={ __( 'Height', 'elementor' ) } />
15
- </Grid>
16
- <Grid container spacing={ 2 }>
17
- <Control bind="min-width" label={ __( 'Min. Width', 'elementor' ) } />
18
- <Control bind="min-height" label={ __( 'Min. Height', 'elementor' ) } />
19
- </Grid>
20
- <Grid container spacing={ 2 }>
21
- <Control bind="max-width" label={ __( 'Max. Width', 'elementor' ) } />
22
- <Control bind="max-height" label={ __( 'Max. Height', 'elementor' ) } />
23
- </Grid>
24
- </Stack>
25
- </AccordionSection>
26
- );
27
- };
28
-
29
- type ControlProps = {
30
- bind: StyleControlProps[ 'bind' ];
31
- label: string;
32
- };
33
-
34
- const Control = ( { label, bind }: ControlProps ) => {
35
- return (
36
- <Grid item xs={ 6 }>
37
- <StyleControl bind={ bind }>
38
- <Grid container spacing={ 1 } alignItems="center">
39
- <Grid item xs={ 12 }>
40
- <StyleControl.Label>{ label }</StyleControl.Label>
41
- </Grid>
42
- <Grid item xs={ 12 }>
43
- <BaseControl type={ 'size' } />
44
- </Grid>
45
- </Grid>
46
- </StyleControl>
47
- </Grid>
48
- );
49
- };
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { __ } from '@wordpress/i18n';
3
- import { Grid } from '@elementor/ui';
4
- import { StyleControl } from '../../../controls/style-control';
5
- import { SizeControl } from '../../../controls/control-types/size-control';
6
-
7
- export const FontSizeControl = () => {
8
- return (
9
- <StyleControl bind="font-size">
10
- <Grid container spacing={ 1 } alignItems="center">
11
- <Grid item xs={ 6 }>
12
- <StyleControl.Label>{ __( 'Font Size', 'elementor' ) }</StyleControl.Label>
13
- </Grid>
14
- <Grid item xs={ 6 }>
15
- <SizeControl />
16
- </Grid>
17
- </Grid>
18
- </StyleControl>
19
- );
20
- };
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { __ } from '@wordpress/i18n';
3
- import { Grid } from '@elementor/ui';
4
- import { StyleControl } from '../../../controls/style-control';
5
- import { SizeControl } from '../../../controls/control-types/size-control';
6
-
7
- export const LetterSpacingControl = () => {
8
- return (
9
- <StyleControl bind="letter-spacing">
10
- <Grid container spacing={ 1 } alignItems="center">
11
- <Grid item xs={ 6 }>
12
- <StyleControl.Label>{ __( 'Letter Spacing', 'elementor' ) }</StyleControl.Label>
13
- </Grid>
14
- <Grid item xs={ 6 }>
15
- <SizeControl />
16
- </Grid>
17
- </Grid>
18
- </StyleControl>
19
- );
20
- };
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { __ } from '@wordpress/i18n';
3
- import { Grid } from '@elementor/ui';
4
- import { StyleControl } from '../../../controls/style-control';
5
- import { ColorControl } from '../../../controls/control-types/color-control';
6
-
7
- export const TextColorControl = () => {
8
- return (
9
- <StyleControl bind="color">
10
- <Grid container spacing={ 1 } alignItems="center">
11
- <Grid item xs={ 6 }>
12
- <StyleControl.Label>{ __( 'Text Color', 'elementor' ) }</StyleControl.Label>
13
- </Grid>
14
- <Grid item xs={ 6 }>
15
- <ColorControl />
16
- </Grid>
17
- </Grid>
18
- </StyleControl>
19
- );
20
- };
@@ -1,20 +0,0 @@
1
- import * as React from 'react';
2
- import { __ } from '@wordpress/i18n';
3
- import { Grid } from '@elementor/ui';
4
- import { StyleControl } from '../../../controls/style-control';
5
- import { SizeControl } from '../../../controls/control-types/size-control';
6
-
7
- export const WordSpacingControl = () => {
8
- return (
9
- <StyleControl bind="word-spacing">
10
- <Grid container spacing={ 1 } alignItems="center">
11
- <Grid item xs={ 6 }>
12
- <StyleControl.Label>{ __( 'Word Spacing', 'elementor' ) }</StyleControl.Label>
13
- </Grid>
14
- <Grid item xs={ 6 }>
15
- <SizeControl />
16
- </Grid>
17
- </Grid>
18
- </StyleControl>
19
- );
20
- };
@@ -1,22 +0,0 @@
1
- import { createContext, useContext } from 'react';
2
- import { PropKey, PropValue } from '../types';
3
-
4
- export type ControlContext< T extends PropValue > = {
5
- bind: PropKey;
6
- setValue: ( value: T | undefined ) => void;
7
- value: T | undefined;
8
- };
9
-
10
- export const ControlContext = createContext< ControlContext< PropValue > | null >( null );
11
-
12
- export function useControl< T extends PropValue >(): ControlContext< T | undefined >;
13
- export function useControl< T extends PropValue >( defaultValue: T ): ControlContext< T >;
14
- export function useControl< T extends PropValue >( defaultValue?: T ) {
15
- const controlContext = useContext< ControlContext< T > >( ControlContext as never );
16
-
17
- if ( ! controlContext ) {
18
- throw new Error( 'useControl must be used within a ControlContext' );
19
- }
20
-
21
- return { ...controlContext, value: controlContext.value ?? defaultValue };
22
- }
@@ -1,34 +0,0 @@
1
- import { PropValue } from '../types';
2
- import { ComponentType } from 'react';
3
- import { useControl } from './control-context';
4
-
5
- type ReplaceWhenParams = {
6
- value: PropValue;
7
- };
8
-
9
- type ControlReplacement = {
10
- component: ComponentType;
11
- condition: ( { value }: ReplaceWhenParams ) => boolean;
12
- };
13
-
14
- let controlReplacement: ControlReplacement | undefined;
15
-
16
- const getControlReplacement = ( { value }: ReplaceWhenParams ) => {
17
- let shouldReplace = false;
18
-
19
- try {
20
- shouldReplace = !! controlReplacement?.condition( { value } ) && !! controlReplacement?.component;
21
- } catch {}
22
-
23
- return shouldReplace ? controlReplacement?.component : undefined;
24
- };
25
-
26
- export function replaceControl( { component, condition }: ControlReplacement ) {
27
- controlReplacement = { component, condition };
28
- }
29
-
30
- export function useControlReplacement() {
31
- const { value } = useControl();
32
-
33
- return getControlReplacement( { value } );
34
- }