@elementor/editor-editing-panel 0.18.0 → 0.19.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 +13 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +381 -330
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +291 -240
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/editing-panel-error-fallback.tsx +12 -0
- package/src/components/editing-panel.tsx +23 -12
- package/src/components/settings-tab.tsx +3 -3
- package/src/components/style-sections/background-section/background-color-control.tsx +20 -0
- package/src/components/style-sections/background-section/background-section.tsx +15 -0
- package/src/components/style-sections/effects-section/box-shadow-repeater.tsx +1 -1
- package/src/components/style-sections/spacing-section/linked-dimensions-control.tsx +1 -1
- package/src/components/style-sections/typography-section/text-alignment-control.tsx +1 -1
- package/src/components/style-sections/typography-section/text-direction-control.tsx +1 -1
- package/src/components/style-sections/typography-section/text-style-control.tsx +1 -1
- package/src/components/style-sections/typography-section/transform-control.tsx +1 -1
- package/src/components/style-tab.tsx +5 -3
- package/src/control-replacement.tsx +3 -0
- package/src/controls/components/text-field-inner-selection.tsx +2 -2
- package/src/controls/control-context.tsx +1 -1
- package/src/controls/control-replacement.ts +1 -1
- package/src/controls/control-types/color-control.tsx +1 -1
- package/src/controls/control-types/image-control.tsx +1 -1
- package/src/controls/control-types/image-media-control.tsx +2 -2
- package/src/controls/control-types/select-control.tsx +1 -1
- package/src/controls/control-types/size-control.tsx +1 -1
- package/src/controls/control-types/toggle-control.tsx +1 -1
- package/src/controls/create-control-replacement.tsx +53 -0
- package/src/controls/create-control.tsx +12 -3
- package/src/controls/hooks/use-style-control.ts +3 -3
- package/src/{hooks → controls/hooks}/use-widget-settings.ts +1 -1
- package/src/{props → controls/props}/is-transformable.ts +1 -2
- package/src/{types.ts → controls/props/types.ts} +0 -38
- package/src/{contexts/element-context.tsx → controls/providers/element-provider.tsx} +4 -4
- package/src/controls/settings-control.tsx +5 -5
- package/src/controls/style-control.tsx +1 -1
- package/src/{sync → controls/sync}/get-container.ts +1 -1
- package/src/{sync → controls/sync}/update-settings.ts +1 -1
- package/src/controls/types.ts +39 -0
- package/src/dynamics/components/dynamic-selection-control.tsx +1 -1
- package/src/dynamics/components/dynamic-selection.tsx +5 -5
- package/src/dynamics/dynamic-control.tsx +1 -1
- package/src/dynamics/hooks/use-dynamic-tag.ts +2 -2
- package/src/dynamics/hooks/use-prop-dynamic-action.tsx +2 -2
- package/src/dynamics/hooks/use-prop-dynamic-tags.ts +3 -3
- package/src/dynamics/hooks/use-prop-value-history.ts +3 -3
- package/src/dynamics/init.ts +1 -1
- package/src/dynamics/types.ts +2 -1
- package/src/dynamics/utils.ts +2 -2
- package/src/hooks/use-element-style-prop.ts +3 -2
- package/src/hooks/use-element-styles.ts +1 -1
- package/src/hooks/use-element-type.ts +1 -1
- package/src/index.ts +1 -1
- package/src/sync/get-element-styles.ts +2 -2
- package/src/sync/get-selected-elements.ts +1 -1
- package/src/sync/types.ts +2 -1
- package/src/sync/update-style.ts +3 -2
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Alert, Box } from '@elementor/ui';
|
|
3
|
+
|
|
4
|
+
export function EditorPanelErrorFallback() {
|
|
5
|
+
return (
|
|
6
|
+
<Box role="alert" sx={ { minHeight: '100%', p: 2 } }>
|
|
7
|
+
<Alert severity="error" sx={ { mb: 2, maxWidth: 400, textAlign: 'center' } }>
|
|
8
|
+
<strong>Something went wrong</strong>
|
|
9
|
+
</Alert>
|
|
10
|
+
</Box>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -1,35 +1,46 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
3
|
import useSelectedElements from '../hooks/use-selected-elements';
|
|
4
|
-
import useElementType from '../hooks/use-element-type';
|
|
5
4
|
import { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';
|
|
6
|
-
import {
|
|
5
|
+
import { ElementProvider } from '../controls/providers/element-provider';
|
|
6
|
+
import useElementType from '../hooks/use-element-type';
|
|
7
7
|
import { EditingPanelTabs } from './editing-panel-tabs';
|
|
8
|
+
import { ControlReplacementProvider } from '../controls/create-control-replacement';
|
|
9
|
+
import { getControlReplacement } from '../control-replacement';
|
|
10
|
+
import { ErrorBoundary } from '@elementor/ui';
|
|
11
|
+
import { EditorPanelErrorFallback } from './editing-panel-error-fallback';
|
|
8
12
|
|
|
9
13
|
export const EditingPanel = () => {
|
|
10
14
|
const elements = useSelectedElements();
|
|
11
15
|
|
|
12
16
|
const [ selectedElement ] = elements;
|
|
13
17
|
|
|
18
|
+
// TODO: Move this into the provider.
|
|
14
19
|
const elementType = useElementType( selectedElement?.type );
|
|
15
20
|
|
|
16
21
|
if ( elements.length !== 1 || ! elementType ) {
|
|
17
22
|
return null;
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
const controlReplacement = getControlReplacement();
|
|
26
|
+
|
|
20
27
|
/* translators: %s: Element type title. */
|
|
21
28
|
const panelTitle = __( 'Edit %s', 'elementor' ).replace( '%s', elementType.title );
|
|
22
29
|
|
|
23
30
|
return (
|
|
24
|
-
<
|
|
25
|
-
<
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
<ErrorBoundary fallback={ <EditorPanelErrorFallback /> }>
|
|
32
|
+
<Panel>
|
|
33
|
+
<PanelHeader>
|
|
34
|
+
<PanelHeaderTitle>{ panelTitle }</PanelHeaderTitle>
|
|
35
|
+
</PanelHeader>
|
|
36
|
+
<PanelBody>
|
|
37
|
+
<ControlReplacementProvider { ...controlReplacement }>
|
|
38
|
+
<ElementProvider element={ selectedElement } elementType={ elementType }>
|
|
39
|
+
<EditingPanelTabs />
|
|
40
|
+
</ElementProvider>
|
|
41
|
+
</ControlReplacementProvider>
|
|
42
|
+
</PanelBody>
|
|
43
|
+
</Panel>
|
|
44
|
+
</ErrorBoundary>
|
|
34
45
|
);
|
|
35
46
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Stack } from '@elementor/ui';
|
|
3
3
|
import { SettingsControl } from '../controls/settings-control';
|
|
4
|
-
import {
|
|
4
|
+
import { useElement } from '../controls/providers/element-provider';
|
|
5
5
|
import { AccordionSection } from './accordion-section';
|
|
6
|
-
import type { Control } from '../types';
|
|
6
|
+
import type { Control } from '../controls/types';
|
|
7
7
|
import { Control as BaseControl } from '../controls/control';
|
|
8
8
|
import { ControlType, getControlByType } from '../controls/controls-registry';
|
|
9
9
|
import { ControlTypeContainer } from '../controls/components/control-type-container';
|
|
10
10
|
|
|
11
11
|
export const SettingsTab = () => {
|
|
12
|
-
const { elementType } =
|
|
12
|
+
const { elementType } = useElement();
|
|
13
13
|
|
|
14
14
|
return (
|
|
15
15
|
<Stack>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { __ } from '@wordpress/i18n';
|
|
3
|
+
import { StyleControl } from '../../../controls/style-control';
|
|
4
|
+
import { Grid } from '@elementor/ui';
|
|
5
|
+
import { ColorControl } from '../../../controls/control-types/color-control';
|
|
6
|
+
|
|
7
|
+
export const BackgroundColorControl = () => {
|
|
8
|
+
return (
|
|
9
|
+
<StyleControl bind="background-color">
|
|
10
|
+
<Grid container spacing={ 1 } alignItems="center">
|
|
11
|
+
<Grid item xs={ 6 }>
|
|
12
|
+
<StyleControl.Label>{ __( 'Color', 'elementor' ) }</StyleControl.Label>
|
|
13
|
+
</Grid>
|
|
14
|
+
<Grid item xs={ 6 }>
|
|
15
|
+
<ColorControl />
|
|
16
|
+
</Grid>
|
|
17
|
+
</Grid>
|
|
18
|
+
</StyleControl>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { __ } from '@wordpress/i18n';
|
|
3
|
+
import { Stack } from '@elementor/ui';
|
|
4
|
+
import { AccordionSection } from '../../accordion-section';
|
|
5
|
+
import { BackgroundColorControl } from './background-color-control';
|
|
6
|
+
|
|
7
|
+
export const BackgroundSection = () => {
|
|
8
|
+
return (
|
|
9
|
+
<AccordionSection title={ __( 'Background', 'elementor' ) }>
|
|
10
|
+
<Stack gap={ 1.5 }>
|
|
11
|
+
<BackgroundColorControl />
|
|
12
|
+
</Stack>
|
|
13
|
+
</AccordionSection>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -3,7 +3,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
3
3
|
import { Grid, Stack, UnstableColorIndicator } from '@elementor/ui';
|
|
4
4
|
import { Repeater } from '../../../controls/components/repeater';
|
|
5
5
|
import { ControlContext, useControl } from '../../../controls/control-context';
|
|
6
|
-
import { PropValue, TransformablePropValue } from '../../../types';
|
|
6
|
+
import { PropValue, TransformablePropValue } from '../../../controls/props/types';
|
|
7
7
|
import { SizeControl, SizeControlValue } from '../../../controls/control-types/size-control';
|
|
8
8
|
import { ColorControl, ColorPropValue } from '../../../controls/control-types/color-control';
|
|
9
9
|
import { ControlLabel } from '../../control-label';
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
3
|
import { Grid, Stack, ToggleButton } from '@elementor/ui';
|
|
4
4
|
import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
|
|
5
|
-
import { PropValue, TransformablePropValue } from '../../../types';
|
|
5
|
+
import { PropValue, TransformablePropValue } from '../../../controls/props/types';
|
|
6
6
|
import { SizeControl } from '../../../controls/control-types/size-control';
|
|
7
7
|
import { ControlLabel } from '../../control-label';
|
|
8
8
|
import { ControlContext, useControl } from '../../../controls/control-context';
|
|
@@ -38,7 +38,7 @@ export const TextAlignmentControl = () => {
|
|
|
38
38
|
<Grid item xs={ 6 }>
|
|
39
39
|
<StyleControl.Label>{ __( 'Alignment', 'elementor' ) }</StyleControl.Label>
|
|
40
40
|
</Grid>
|
|
41
|
-
<Grid item xs={ 6 }>
|
|
41
|
+
<Grid item xs={ 6 } display="flex" justifyContent="end">
|
|
42
42
|
<ToggleControl options={ options } />
|
|
43
43
|
</Grid>
|
|
44
44
|
</Grid>
|
|
@@ -28,7 +28,7 @@ export const TextDirectionControl = () => {
|
|
|
28
28
|
<Grid item xs={ 6 }>
|
|
29
29
|
<StyleControl.Label>{ __( 'Direction', 'elementor' ) }</StyleControl.Label>
|
|
30
30
|
</Grid>
|
|
31
|
-
<Grid item xs={ 6 }>
|
|
31
|
+
<Grid item xs={ 6 } display="flex" justifyContent="end">
|
|
32
32
|
<ToggleControl options={ options } />
|
|
33
33
|
</Grid>
|
|
34
34
|
</Grid>
|
|
@@ -18,7 +18,7 @@ export const TextStyleControl = () => {
|
|
|
18
18
|
<Grid item xs={ 6 }>
|
|
19
19
|
<ControlLabel>{ __( 'Style', 'elementor' ) }</ControlLabel>
|
|
20
20
|
</Grid>
|
|
21
|
-
<Grid item xs={ 6 }>
|
|
21
|
+
<Grid item xs={ 6 } display="flex" justifyContent="end">
|
|
22
22
|
<ToggleButtonGroup value={ formats }>
|
|
23
23
|
<ToggleButton
|
|
24
24
|
value="italic"
|
|
@@ -17,7 +17,7 @@ export const TransformControl = () => (
|
|
|
17
17
|
<Grid item xs={ 6 }>
|
|
18
18
|
<StyleControl.Label>{ __( 'Transform', 'elementor' ) }</StyleControl.Label>
|
|
19
19
|
</Grid>
|
|
20
|
-
<Grid item xs={ 6 }>
|
|
20
|
+
<Grid item xs={ 6 } display="flex" justifyContent="end">
|
|
21
21
|
<ToggleControl options={ options } />
|
|
22
22
|
</Grid>
|
|
23
23
|
</Grid>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { StyleContext } from '../contexts/style-context';
|
|
3
|
-
import {
|
|
3
|
+
import { useElement } from '../controls/providers/element-provider';
|
|
4
4
|
import { useElementStyles } from '../hooks/use-element-styles';
|
|
5
5
|
import { Stack } from '@elementor/ui';
|
|
6
6
|
import { SizeSection } from './style-sections/size-section';
|
|
@@ -9,6 +9,7 @@ import { PositionSection } from './style-sections/position-section/position-sect
|
|
|
9
9
|
import { StyleDefinition } from '@elementor/editor-style';
|
|
10
10
|
import { SpacingSection } from './style-sections/spacing-section/spacing-section';
|
|
11
11
|
import { EffectsSection } from './style-sections/effects-section/effects-section';
|
|
12
|
+
import { BackgroundSection } from './style-sections/background-section/background-section';
|
|
12
13
|
|
|
13
14
|
const CLASSES_PROP_KEY = 'classes';
|
|
14
15
|
|
|
@@ -22,6 +23,7 @@ export const StyleTab = () => {
|
|
|
22
23
|
<SizeSection />
|
|
23
24
|
<PositionSection />
|
|
24
25
|
<TypographySection />
|
|
26
|
+
<BackgroundSection />
|
|
25
27
|
<SpacingSection />
|
|
26
28
|
<EffectsSection />
|
|
27
29
|
</Stack>
|
|
@@ -30,7 +32,7 @@ export const StyleTab = () => {
|
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
function useClassesProp(): string {
|
|
33
|
-
const { elementType } =
|
|
35
|
+
const { elementType } = useElement();
|
|
34
36
|
|
|
35
37
|
const prop = Object.entries( elementType.propsSchema ).find(
|
|
36
38
|
( [ , propType ] ) => propType.kind === 'array' && propType.key === CLASSES_PROP_KEY
|
|
@@ -44,7 +46,7 @@ function useClassesProp(): string {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
function useStyleDefinition(): StyleDefinition | null {
|
|
47
|
-
const { element } =
|
|
49
|
+
const { element } = useElement();
|
|
48
50
|
const elementStyles = useElementStyles( element.id );
|
|
49
51
|
|
|
50
52
|
return Object.values( elementStyles || {} )[ 0 ] ?? null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PropValue } from '../../types';
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import { bindMenu, bindTrigger, Button, InputAdornment, Menu, MenuItem, TextField, usePopupState } from '@elementor/ui';
|
|
4
2
|
import { useId } from 'react';
|
|
3
|
+
import { bindMenu, bindTrigger, Button, InputAdornment, Menu, MenuItem, TextField, usePopupState } from '@elementor/ui';
|
|
4
|
+
import { PropValue } from '../props/types';
|
|
5
5
|
|
|
6
6
|
export type TextFieldInnerSelectionProps = {
|
|
7
7
|
placeholder?: string;
|
|
@@ -3,7 +3,7 @@ import { UnstableColorPicker, UnstableColorPickerProps } from '@elementor/ui';
|
|
|
3
3
|
import { useControl } from '../control-context';
|
|
4
4
|
import ControlActions from '../control-actions/control-actions';
|
|
5
5
|
import { createControl } from '../create-control';
|
|
6
|
-
import { TransformablePropValue } from '
|
|
6
|
+
import { TransformablePropValue } from '../props/types';
|
|
7
7
|
|
|
8
8
|
export type ColorPropValue = TransformablePropValue< 'color', string >;
|
|
9
9
|
|
|
@@ -3,8 +3,8 @@ import { Grid, Stack } from '@elementor/ui';
|
|
|
3
3
|
import { __ } from '@wordpress/i18n';
|
|
4
4
|
import { ControlContext, useControl } from '../control-context';
|
|
5
5
|
import { type ImageSrc, ImageMediaControl } from './image-media-control';
|
|
6
|
+
import { PropValue, TransformablePropValue } from '../props/types';
|
|
6
7
|
import { SettingsControl } from '../settings-control';
|
|
7
|
-
import { PropValue, TransformablePropValue } from '../../types';
|
|
8
8
|
import { SelectControl } from './select-control';
|
|
9
9
|
import { createControl } from '../create-control';
|
|
10
10
|
|
|
@@ -2,11 +2,11 @@ import * as React from 'react';
|
|
|
2
2
|
import { Button, Card, CardMedia, CardOverlay, Stack } from '@elementor/ui';
|
|
3
3
|
import { UploadIcon } from '@elementor/icons';
|
|
4
4
|
import { useWpMediaAttachment, useWpMediaFrame } from '@elementor/wp-media';
|
|
5
|
-
import { useControl } from '../control-context';
|
|
6
|
-
import { TransformablePropValue } from '../../types';
|
|
7
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { useControl } from '../control-context';
|
|
8
7
|
import ControlActions from '../control-actions/control-actions';
|
|
9
8
|
import { createControl } from '../create-control';
|
|
9
|
+
import { TransformablePropValue } from '../props/types';
|
|
10
10
|
|
|
11
11
|
type ImageAttachmentID = TransformablePropValue< 'image-attachment-id', number >;
|
|
12
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';
|
|
3
3
|
import { useControl } from '../control-context';
|
|
4
|
-
import { PropValue } from '
|
|
4
|
+
import { PropValue } from '../props/types';
|
|
5
5
|
import ControlActions from '../control-actions/control-actions';
|
|
6
6
|
import { createControl } from '../create-control';
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InputAdornment } from '@elementor/ui';
|
|
3
|
-
import { TransformablePropValue } from '
|
|
3
|
+
import { TransformablePropValue } from '../props/types';
|
|
4
4
|
import { useControl } from '../control-context';
|
|
5
5
|
import { useSyncExternalState } from '../hooks/use-sync-external-state';
|
|
6
6
|
import { SelectionEndAdornment, TextFieldInnerSelection } from '../components/text-field-inner-selection';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useControl } from '../control-context';
|
|
3
3
|
import { ControlToggleButtonGroup, ToggleButtonGroupItem } from '../components/control-toggle-button-group';
|
|
4
|
-
import { PropValue } from '
|
|
4
|
+
import { PropValue } from '../props/types';
|
|
5
5
|
import { createControl } from '../create-control';
|
|
6
6
|
|
|
7
7
|
type ToggleControlProps< T extends PropValue > = {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PropValue } from './props/types';
|
|
3
|
+
import { ComponentType, createContext, useContext } from 'react';
|
|
4
|
+
import { useControl } from './control-context';
|
|
5
|
+
|
|
6
|
+
export type ReplaceWhenParams = {
|
|
7
|
+
value: PropValue;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type CreateControlReplacement = {
|
|
11
|
+
component: ComponentType;
|
|
12
|
+
condition: ( { value }: ReplaceWhenParams ) => boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ControlReplacementContext = createContext< CreateControlReplacement | undefined >( undefined );
|
|
16
|
+
|
|
17
|
+
export const ControlReplacementProvider = ( {
|
|
18
|
+
component,
|
|
19
|
+
condition,
|
|
20
|
+
children,
|
|
21
|
+
}: React.PropsWithChildren< CreateControlReplacement > ) => {
|
|
22
|
+
return (
|
|
23
|
+
<ControlReplacementContext.Provider value={ { component, condition } }>
|
|
24
|
+
{ children }
|
|
25
|
+
</ControlReplacementContext.Provider>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export const useControlReplacement = () => {
|
|
29
|
+
const { value } = useControl();
|
|
30
|
+
const controlReplacement = useContext( ControlReplacementContext );
|
|
31
|
+
|
|
32
|
+
let shouldReplace = false;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
shouldReplace = !! controlReplacement?.condition( { value } ) && !! controlReplacement.component;
|
|
36
|
+
} catch {}
|
|
37
|
+
|
|
38
|
+
return shouldReplace ? controlReplacement?.component : undefined;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createControlReplacement = () => {
|
|
42
|
+
let controlReplacement: CreateControlReplacement;
|
|
43
|
+
|
|
44
|
+
function replaceControl( { component, condition }: CreateControlReplacement ) {
|
|
45
|
+
controlReplacement = { component, condition };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getControlReplacement() {
|
|
49
|
+
return controlReplacement;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { replaceControl, getControlReplacement };
|
|
53
|
+
};
|
|
@@ -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
|
|
27
|
+
return (
|
|
28
|
+
<ErrorBoundary fallback={ null }>
|
|
29
|
+
<ControlReplacement { ...props } />
|
|
30
|
+
</ErrorBoundary>
|
|
31
|
+
);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
return
|
|
34
|
+
return (
|
|
35
|
+
<ErrorBoundary fallback={ null }>
|
|
36
|
+
<Component { ...props } />
|
|
37
|
+
</ErrorBoundary>
|
|
38
|
+
);
|
|
30
39
|
} ) as ControlComponent< T >;
|
|
31
40
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useElement } from '../providers/element-provider';
|
|
2
2
|
import { useStyleContext } from '../../contexts/style-context';
|
|
3
3
|
import { useElementStyleProp } from '../../hooks/use-element-style-prop';
|
|
4
4
|
import { updateStyle } from '../../sync/update-style';
|
|
5
|
-
import { PropKey, PropValue } from '
|
|
5
|
+
import { PropKey, PropValue } from '../props/types';
|
|
6
6
|
|
|
7
7
|
export const useStyleControl = < T extends PropValue >( propName: PropKey ) => {
|
|
8
|
-
const { element } =
|
|
8
|
+
const { element } = useElement();
|
|
9
9
|
const { selectedStyleDef, selectedMeta, selectedClassesProp } = useStyleContext();
|
|
10
10
|
|
|
11
11
|
const value = useElementStyleProp< T >( {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';
|
|
2
|
-
import { PropValue } from '../types';
|
|
3
2
|
import getContainer from '../sync/get-container';
|
|
3
|
+
import { PropValue } from '../props/types';
|
|
4
4
|
|
|
5
5
|
export const useWidgetSettings = ( { id, bind }: { id: string; bind: string } ): PropValue => {
|
|
6
6
|
return useListenTo(
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
export type ElementID = string;
|
|
2
|
-
|
|
3
|
-
export type Element = {
|
|
4
|
-
id: ElementID;
|
|
5
|
-
type: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type ElementType = {
|
|
9
|
-
key: string;
|
|
10
|
-
controls: ControlItem[];
|
|
11
|
-
propsSchema: PropsSchema;
|
|
12
|
-
title: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type ControlsSection = {
|
|
16
|
-
type: 'section';
|
|
17
|
-
value: {
|
|
18
|
-
description?: string;
|
|
19
|
-
label: string;
|
|
20
|
-
items: ControlItem[];
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type Control = {
|
|
25
|
-
type: 'control';
|
|
26
|
-
value: {
|
|
27
|
-
bind: string;
|
|
28
|
-
label?: string;
|
|
29
|
-
description?: string;
|
|
30
|
-
type: string;
|
|
31
|
-
props: Record< string, unknown >;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type ControlItem = ControlsSection | Control;
|
|
36
|
-
|
|
37
1
|
type PropTypeKey = string;
|
|
38
2
|
|
|
39
3
|
type BasePropType = {
|
|
@@ -68,8 +32,6 @@ export type UnionPropType = BasePropType & {
|
|
|
68
32
|
|
|
69
33
|
export type PropType = TransformablePropType | UnionPropType;
|
|
70
34
|
|
|
71
|
-
export type PropsSchema = Record< Control[ 'value' ][ 'bind' ], PropType >;
|
|
72
|
-
|
|
73
35
|
type MaybeArray< T > = T | T[];
|
|
74
36
|
|
|
75
37
|
export type TransformablePropValue< Type extends string, Value = unknown > = {
|
|
@@ -11,19 +11,19 @@ const Context = createContext< ContextValue | null >( null );
|
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
13
13
|
element: Element;
|
|
14
|
-
elementType: ElementType;
|
|
15
14
|
children?: ReactNode;
|
|
15
|
+
elementType: ElementType;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export function
|
|
18
|
+
export function ElementProvider( { children, element, elementType }: Props ) {
|
|
19
19
|
return <Context.Provider value={ { element, elementType } }>{ children }</Context.Provider>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function
|
|
22
|
+
export function useElement() {
|
|
23
23
|
const context = useContext( Context );
|
|
24
24
|
|
|
25
25
|
if ( ! context ) {
|
|
26
|
-
throw new Error( '
|
|
26
|
+
throw new Error( 'useElement must be used within a ElementProvider' );
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return context;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ControlContext } from './control-context';
|
|
3
|
-
import { PropKey, PropValue } from '
|
|
4
|
-
import {
|
|
5
|
-
import { useWidgetSettings } from '
|
|
6
|
-
import { updateSettings } from '
|
|
3
|
+
import { PropKey, PropValue } from './props/types';
|
|
4
|
+
import { useElement } from './providers/element-provider';
|
|
5
|
+
import { useWidgetSettings } from './hooks/use-widget-settings';
|
|
6
|
+
import { updateSettings } from './sync/update-settings';
|
|
7
7
|
import { ControlLabel } from '../components/control-label';
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
@@ -12,7 +12,7 @@ type Props = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
const SettingsControl = ( { bind, children }: Props ) => {
|
|
15
|
-
const { element, elementType } =
|
|
15
|
+
const { element, elementType } = useElement();
|
|
16
16
|
|
|
17
17
|
const defaultValue = elementType.propsSchema[ bind ]?.default;
|
|
18
18
|
const settingsValue = useWidgetSettings( { id: element.id, bind } );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { PropKey } from '
|
|
2
|
+
import { PropKey } from './props/types';
|
|
3
3
|
import { ControlContext } from '../controls/control-context';
|
|
4
4
|
import { ControlLabel } from '../components/control-label';
|
|
5
5
|
import { useStyleControl } from './hooks/use-style-control';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
2
|
-
import { Props } from '../types';
|
|
2
|
+
import { Props } from '../props/types';
|
|
3
3
|
import getContainer from './get-container';
|
|
4
4
|
|
|
5
5
|
export const updateSettings = ( { id, props }: { id: string; props: Props } ) => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PropType } from './props/types';
|
|
2
|
+
|
|
3
|
+
export type ElementID = string;
|
|
4
|
+
|
|
5
|
+
export type Element = {
|
|
6
|
+
id: ElementID;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ElementType = {
|
|
11
|
+
key: string;
|
|
12
|
+
controls: ControlItem[];
|
|
13
|
+
propsSchema: PropsSchema;
|
|
14
|
+
title: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ControlsSection = {
|
|
18
|
+
type: 'section';
|
|
19
|
+
value: {
|
|
20
|
+
description?: string;
|
|
21
|
+
label: string;
|
|
22
|
+
items: ControlItem[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type Control = {
|
|
27
|
+
type: 'control';
|
|
28
|
+
value: {
|
|
29
|
+
bind: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
type: string;
|
|
33
|
+
props: Record< string, unknown >;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ControlItem = ControlsSection | Control;
|
|
38
|
+
|
|
39
|
+
export type PropsSchema = Record< Control[ 'value' ][ 'bind' ], PropType >;
|
|
@@ -4,7 +4,7 @@ import { useControl } from '../../controls/control-context';
|
|
|
4
4
|
import { DynamicPropValue, DynamicTag } from '../types';
|
|
5
5
|
import { DynamicControl } from '../dynamic-control';
|
|
6
6
|
import { DatabaseIcon, SettingsIcon, XIcon } from '@elementor/icons';
|
|
7
|
-
import type { Control, ControlsSection } from '../../types';
|
|
7
|
+
import type { Control, ControlsSection } from '../../controls/types';
|
|
8
8
|
import { DynamicSelection } from './dynamic-selection';
|
|
9
9
|
import { ControlType, getControlByType } from '../../controls/controls-registry';
|
|
10
10
|
import { ControlLabel } from '../../components/control-label';
|