@elementor/editor-editing-panel 0.15.0 → 0.16.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 +30 -0
- package/dist/index.js +693 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +711 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
- package/src/components/style-sections/position-section/position-section.tsx +15 -0
- package/src/components/style-sections/position-section/z-index-control.tsx +16 -0
- package/src/components/style-sections/size-section.tsx +9 -12
- package/src/components/style-sections/spacing-section/linked-dimensions-control.tsx +140 -0
- package/src/components/style-sections/spacing-section/spacing-section.tsx +22 -0
- package/src/components/style-sections/typography-section/letter-spacing-control.tsx +16 -0
- package/src/components/style-sections/typography-section/text-color-control.tsx +16 -0
- package/src/components/style-sections/typography-section/transform-control.tsx +23 -0
- package/src/components/style-sections/typography-section/typography-section.tsx +15 -1
- package/src/components/style-sections/typography-section/word-spacing-control.tsx +16 -0
- package/src/components/style-tab.tsx +29 -5
- package/src/contexts/style-context.tsx +8 -2
- package/src/controls/components/control-toggle-button-group.tsx +59 -0
- package/src/controls/components/text-field-inner-selection.tsx +79 -0
- package/src/controls/control-types/color-control.tsx +24 -0
- package/src/controls/control-types/number-control.tsx +25 -0
- package/src/controls/control-types/size-control.tsx +20 -34
- package/src/controls/control-types/toggle-control.tsx +25 -0
- package/src/controls/hooks/use-style-control.ts +2 -1
- package/src/controls/settings-control.tsx +1 -1
- package/src/dynamics/components/dynamic-selection-control.tsx +180 -0
- package/src/dynamics/components/dynamic-selection.tsx +144 -0
- package/src/dynamics/dynamic-control.tsx +42 -0
- package/src/dynamics/hooks/use-dynamic-tag.ts +10 -0
- package/src/{hooks/use-dynamic-tags-config.ts → dynamics/hooks/use-prop-dynamic-tags.ts} +6 -5
- package/src/dynamics/init.ts +10 -0
- package/src/{sync → dynamics/sync}/get-atomic-dynamic-tags.ts +1 -1
- package/src/{sync → dynamics/sync}/get-elementor-config.ts +1 -1
- package/src/dynamics/types.ts +32 -0
- package/src/dynamics/utils.ts +9 -0
- package/src/init.ts +4 -0
- package/src/props/is-transformable.ts +14 -0
- package/src/sync/types.ts +0 -13
- package/src/sync/update-style.ts +2 -2
- package/src/types.ts +9 -6
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { useControl } from '../../controls/control-context';
|
|
4
|
+
import { DynamicPropValue, DynamicTag } from '../types';
|
|
5
|
+
import { DynamicControl } from '../dynamic-control';
|
|
6
|
+
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
|
+
import {
|
|
14
|
+
bindPopover,
|
|
15
|
+
bindTrigger,
|
|
16
|
+
Box,
|
|
17
|
+
IconButton,
|
|
18
|
+
Paper,
|
|
19
|
+
Popover,
|
|
20
|
+
Stack,
|
|
21
|
+
Typography,
|
|
22
|
+
UnstableTag as Tag,
|
|
23
|
+
usePopupState,
|
|
24
|
+
Tabs,
|
|
25
|
+
Divider,
|
|
26
|
+
useTabs,
|
|
27
|
+
Tab,
|
|
28
|
+
TabPanel,
|
|
29
|
+
} from '@elementor/ui';
|
|
30
|
+
import { __ } from '@wordpress/i18n';
|
|
31
|
+
|
|
32
|
+
const SIZE = 'tiny';
|
|
33
|
+
|
|
34
|
+
export const DynamicSelectionControl = () => {
|
|
35
|
+
const { bind, value, setValue } = useControl< DynamicPropValue | null >();
|
|
36
|
+
const { name: tagName = '' } = value?.value || {};
|
|
37
|
+
|
|
38
|
+
const selectionPopoverId = useId();
|
|
39
|
+
const selectionPopoverState = usePopupState( { variant: 'popover', popupId: selectionPopoverId } );
|
|
40
|
+
|
|
41
|
+
const dynamicTag = useDynamicTag( bind, tagName );
|
|
42
|
+
|
|
43
|
+
const removeDynamicTag = () => {
|
|
44
|
+
// TODO: Implement static value restoration.
|
|
45
|
+
setValue( null );
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if ( ! dynamicTag ) {
|
|
49
|
+
throw new Error( `Dynamic tag ${ tagName } not found` );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Box sx={ { width: '100%' } }>
|
|
54
|
+
<Tag
|
|
55
|
+
fullWidth
|
|
56
|
+
showActionsOnHover
|
|
57
|
+
label={ dynamicTag.label }
|
|
58
|
+
startIcon={ <DatabaseIcon fontSize={ SIZE } /> }
|
|
59
|
+
{ ...bindTrigger( selectionPopoverState ) }
|
|
60
|
+
actions={
|
|
61
|
+
<>
|
|
62
|
+
<DynamicSettingsPopover dynamicTag={ dynamicTag } />
|
|
63
|
+
<IconButton
|
|
64
|
+
size={ SIZE }
|
|
65
|
+
onClick={ removeDynamicTag }
|
|
66
|
+
aria-label={ __( 'Remove dynamic value', 'elementor' ) }
|
|
67
|
+
>
|
|
68
|
+
<XIcon fontSize={ SIZE } />
|
|
69
|
+
</IconButton>
|
|
70
|
+
</>
|
|
71
|
+
}
|
|
72
|
+
/>
|
|
73
|
+
<Popover
|
|
74
|
+
disablePortal
|
|
75
|
+
disableScrollLock
|
|
76
|
+
anchorOrigin={ { vertical: 'bottom', horizontal: 'left' } }
|
|
77
|
+
{ ...bindPopover( selectionPopoverState ) }
|
|
78
|
+
>
|
|
79
|
+
<Stack>
|
|
80
|
+
<Stack direction="row" alignItems="center" pl={ 1.5 } pr={ 0.5 } py={ 1.5 }>
|
|
81
|
+
<DatabaseIcon fontSize={ SIZE } sx={ { mr: 0.5 } } />
|
|
82
|
+
<Typography variant="subtitle2">{ __( 'Dynamic Tags', 'elementor' ) }</Typography>
|
|
83
|
+
<IconButton size={ SIZE } sx={ { ml: 'auto' } } onClick={ selectionPopoverState.close }>
|
|
84
|
+
<XIcon fontSize={ SIZE } />
|
|
85
|
+
</IconButton>
|
|
86
|
+
</Stack>
|
|
87
|
+
<DynamicSelection onSelect={ selectionPopoverState.close } />
|
|
88
|
+
</Stack>
|
|
89
|
+
</Popover>
|
|
90
|
+
</Box>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const DynamicSettingsPopover = ( { dynamicTag }: { dynamicTag: DynamicTag } ) => {
|
|
95
|
+
const popupId = useId();
|
|
96
|
+
const settingsPopupState = usePopupState( { variant: 'popover', popupId } );
|
|
97
|
+
|
|
98
|
+
const hasDynamicSettings = !! dynamicTag.atomic_controls.length;
|
|
99
|
+
|
|
100
|
+
if ( ! hasDynamicSettings ) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
<IconButton
|
|
107
|
+
size={ SIZE }
|
|
108
|
+
{ ...bindTrigger( settingsPopupState ) }
|
|
109
|
+
aria-label={ __( 'Settings', 'elementor' ) }
|
|
110
|
+
>
|
|
111
|
+
<SettingsIcon fontSize={ SIZE } />
|
|
112
|
+
</IconButton>
|
|
113
|
+
<Popover
|
|
114
|
+
disableScrollLock
|
|
115
|
+
anchorOrigin={ { vertical: 'bottom', horizontal: 'center' } }
|
|
116
|
+
{ ...bindPopover( settingsPopupState ) }
|
|
117
|
+
>
|
|
118
|
+
<Paper component={ Stack } sx={ { minHeight: '300px', width: '220px' } }>
|
|
119
|
+
<Stack direction="row" alignItems="center" px={ 1.5 } pt={ 2 } pb={ 1 }>
|
|
120
|
+
<DatabaseIcon fontSize={ SIZE } sx={ { mr: 0.5 } } />
|
|
121
|
+
<Typography variant="subtitle2">{ dynamicTag.label }</Typography>
|
|
122
|
+
<IconButton sx={ { ml: 'auto' } } size={ SIZE } onClick={ settingsPopupState.close }>
|
|
123
|
+
<XIcon fontSize={ SIZE } />
|
|
124
|
+
</IconButton>
|
|
125
|
+
</Stack>
|
|
126
|
+
<DynamicSettings controls={ dynamicTag.atomic_controls } />
|
|
127
|
+
</Paper>
|
|
128
|
+
</Popover>
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const DynamicSettings = ( { controls }: { controls: DynamicTag[ 'atomic_controls' ] } ) => {
|
|
134
|
+
const tabs = controls.filter( ( { type } ) => type === 'section' ) as ControlsSection[];
|
|
135
|
+
const { getTabsProps, getTabProps, getTabPanelProps } = useTabs< number >( 0 );
|
|
136
|
+
|
|
137
|
+
if ( ! tabs.length ) {
|
|
138
|
+
// Dynamic must have hierarchical controls.
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<Tabs indicatorColor="secondary" textColor="secondary" { ...getTabsProps() }>
|
|
145
|
+
{ tabs.map( ( { value }, index ) => (
|
|
146
|
+
<Tab key={ index } label={ value.label } sx={ { px: 1, py: 0.5 } } { ...getTabProps( index ) } />
|
|
147
|
+
) ) }
|
|
148
|
+
</Tabs>
|
|
149
|
+
<Divider />
|
|
150
|
+
|
|
151
|
+
{ tabs.map( ( { value }, index ) => {
|
|
152
|
+
return (
|
|
153
|
+
<TabPanel key={ index } sx={ { flexGrow: 1 } } { ...getTabPanelProps( index ) }>
|
|
154
|
+
<Stack gap={ 1 } px={ 2 }>
|
|
155
|
+
{ value.items.map( ( item ) => {
|
|
156
|
+
if ( item.type === 'control' ) {
|
|
157
|
+
return <Control key={ item.value.bind } control={ item.value } />;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
} ) }
|
|
161
|
+
</Stack>
|
|
162
|
+
</TabPanel>
|
|
163
|
+
);
|
|
164
|
+
} ) }
|
|
165
|
+
</>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const Control = ( { control }: { control: Control[ 'value' ] } ) => {
|
|
170
|
+
if ( ! getControlByType( control.type as ControlType ) ) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<DynamicControl bind={ control.bind }>
|
|
176
|
+
{ control.label ? <ControlLabel>{ control.label }</ControlLabel> : null }
|
|
177
|
+
<BaseControl type={ control.type as ControlType } props={ control.props } />
|
|
178
|
+
</DynamicControl>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
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';
|
|
7
|
+
import { SearchIcon, PhotoIcon } from '@elementor/icons';
|
|
8
|
+
import {
|
|
9
|
+
Box,
|
|
10
|
+
Divider,
|
|
11
|
+
InputAdornment,
|
|
12
|
+
Link,
|
|
13
|
+
ListSubheader,
|
|
14
|
+
MenuItem,
|
|
15
|
+
MenuList,
|
|
16
|
+
Stack,
|
|
17
|
+
TextField,
|
|
18
|
+
Typography,
|
|
19
|
+
} from '@elementor/ui';
|
|
20
|
+
import { __ } from '@wordpress/i18n';
|
|
21
|
+
import { PropKey } from '../../types';
|
|
22
|
+
|
|
23
|
+
type Option = {
|
|
24
|
+
label: string;
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type OptionEntry = [ string, Option[] ];
|
|
29
|
+
|
|
30
|
+
const SIZE = 'tiny';
|
|
31
|
+
|
|
32
|
+
export type DynamicSelectionProps = {
|
|
33
|
+
onSelect?: () => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
|
|
37
|
+
const [ searchValue, setSearchValue ] = useState( '' );
|
|
38
|
+
|
|
39
|
+
const { groups: dynamicGroups } = getAtomicDynamicTags() || {};
|
|
40
|
+
const { bind, value: dynamicValue, setValue } = useControl< DynamicPropValue >();
|
|
41
|
+
|
|
42
|
+
const options = useFilteredOptions( bind, searchValue );
|
|
43
|
+
|
|
44
|
+
const handleSearch = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
45
|
+
setSearchValue( event.target.value );
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Stack>
|
|
50
|
+
<Box px={ 1.5 } pb={ 1 }>
|
|
51
|
+
<TextField
|
|
52
|
+
fullWidth
|
|
53
|
+
size={ SIZE }
|
|
54
|
+
value={ searchValue }
|
|
55
|
+
onChange={ handleSearch }
|
|
56
|
+
placeholder={ __( 'Search dynamic tag', 'elementor' ) }
|
|
57
|
+
InputProps={ {
|
|
58
|
+
startAdornment: (
|
|
59
|
+
<InputAdornment position="start">
|
|
60
|
+
<SearchIcon fontSize={ SIZE } />
|
|
61
|
+
</InputAdornment>
|
|
62
|
+
),
|
|
63
|
+
} }
|
|
64
|
+
/>
|
|
65
|
+
</Box>
|
|
66
|
+
<Divider />
|
|
67
|
+
<Box sx={ { overflowY: 'auto', height: 260, width: 220 } }>
|
|
68
|
+
{ options.length > 0 ? (
|
|
69
|
+
<MenuList role="listbox" tabIndex={ 0 }>
|
|
70
|
+
{ options.map( ( [ category, items ], index ) => (
|
|
71
|
+
<Fragment key={ index }>
|
|
72
|
+
<ListSubheader sx={ { typography: 'caption', color: 'text.tertiary' } }>
|
|
73
|
+
{ dynamicGroups?.[ category ]?.title || category }
|
|
74
|
+
</ListSubheader>
|
|
75
|
+
{ items.map( ( { value, label: tagLabel } ) => {
|
|
76
|
+
const isSelected = value === dynamicValue?.value?.name;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<MenuItem
|
|
80
|
+
key={ value }
|
|
81
|
+
selected={ isSelected }
|
|
82
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
83
|
+
autoFocus={ isSelected }
|
|
84
|
+
sx={ { typography: 'caption' } }
|
|
85
|
+
onClick={ () => {
|
|
86
|
+
setValue( { $$type: 'dynamic', value: { name: value } } );
|
|
87
|
+
onSelect?.();
|
|
88
|
+
} }
|
|
89
|
+
>
|
|
90
|
+
{ tagLabel }
|
|
91
|
+
</MenuItem>
|
|
92
|
+
);
|
|
93
|
+
} ) }
|
|
94
|
+
</Fragment>
|
|
95
|
+
) ) }
|
|
96
|
+
</MenuList>
|
|
97
|
+
) : (
|
|
98
|
+
<Stack alignItems="center" p={ 2.5 } gap={ 1.5 }>
|
|
99
|
+
<PhotoIcon fontSize="large" />
|
|
100
|
+
<Typography align="center" variant="caption" color="text.secondary">
|
|
101
|
+
{ __( 'Sorry, nothing matched', 'elementor' ) }
|
|
102
|
+
<br />
|
|
103
|
+
“{ searchValue }”.
|
|
104
|
+
</Typography>
|
|
105
|
+
<Typography align="center" variant="caption" color="text.secondary">
|
|
106
|
+
<Link
|
|
107
|
+
color="secondary"
|
|
108
|
+
variant="caption"
|
|
109
|
+
component="button"
|
|
110
|
+
onClick={ () => setSearchValue( '' ) }
|
|
111
|
+
>
|
|
112
|
+
{ __( 'Clear the filters', 'elementor' ) }
|
|
113
|
+
</Link>
|
|
114
|
+
|
|
115
|
+
{ __( 'and try again.', 'elementor' ) }
|
|
116
|
+
</Typography>
|
|
117
|
+
</Stack>
|
|
118
|
+
) }
|
|
119
|
+
</Box>
|
|
120
|
+
</Stack>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const useFilteredOptions = ( bind: PropKey, searchValue: string ): OptionEntry[] => {
|
|
125
|
+
const dynamicTags = usePropDynamicTags( bind );
|
|
126
|
+
|
|
127
|
+
const options = dynamicTags.reduce< Map< string, Option[] > >( ( categories, { name, label, group } ) => {
|
|
128
|
+
const isVisible = label.toLowerCase().includes( searchValue.trim().toLowerCase() );
|
|
129
|
+
|
|
130
|
+
if ( ! isVisible ) {
|
|
131
|
+
return categories;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if ( ! categories.has( group ) ) {
|
|
135
|
+
categories.set( group, [] );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
categories.get( group )?.push( { label, value: name } );
|
|
139
|
+
|
|
140
|
+
return categories;
|
|
141
|
+
}, new Map() );
|
|
142
|
+
|
|
143
|
+
return [ ...options ];
|
|
144
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ControlContext, useControl } from '../controls/control-context';
|
|
3
|
+
import { PropKey, PropValue } from '../types';
|
|
4
|
+
import { useDynamicTag } from './hooks/use-dynamic-tag';
|
|
5
|
+
import { DynamicPropValue } from './types';
|
|
6
|
+
|
|
7
|
+
export type DynamicControlProps = React.PropsWithChildren< {
|
|
8
|
+
bind: PropKey;
|
|
9
|
+
} >;
|
|
10
|
+
|
|
11
|
+
export const DynamicControl = ( { bind, children }: DynamicControlProps ) => {
|
|
12
|
+
const { value, setValue, bind: propName } = useControl< DynamicPropValue >();
|
|
13
|
+
const { name = '', settings } = value?.value ?? {};
|
|
14
|
+
|
|
15
|
+
const dynamicTag = useDynamicTag( propName, name );
|
|
16
|
+
|
|
17
|
+
if ( ! dynamicTag ) {
|
|
18
|
+
throw new Error( `Dynamic tag ${ name } not found` );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const defaultValue = dynamicTag.props_schema[ bind ]?.type.default;
|
|
22
|
+
const dynamicValue = settings?.[ bind ] ?? defaultValue;
|
|
23
|
+
|
|
24
|
+
const setDynamicValue = ( newValue: PropValue ) => {
|
|
25
|
+
setValue( {
|
|
26
|
+
$$type: 'dynamic',
|
|
27
|
+
value: {
|
|
28
|
+
name,
|
|
29
|
+
settings: {
|
|
30
|
+
...settings,
|
|
31
|
+
[ bind ]: newValue,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
} );
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<ControlContext.Provider value={ { setValue: setDynamicValue, value: dynamicValue, bind } }>
|
|
39
|
+
{ children }
|
|
40
|
+
</ControlContext.Provider>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { usePropDynamicTags } from './use-prop-dynamic-tags';
|
|
2
|
+
import { DynamicTag } from '../types';
|
|
3
|
+
import { PropKey } from '../../types';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
|
|
6
|
+
export const useDynamicTag = ( propName: PropKey, tagName: string ): DynamicTag | null => {
|
|
7
|
+
const dynamicTags = usePropDynamicTags( propName );
|
|
8
|
+
|
|
9
|
+
return useMemo( () => dynamicTags.find( ( tag ) => tag.name === tagName ) ?? null, [ dynamicTags, tagName ] );
|
|
10
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { useElementContext } from '
|
|
3
|
-
import { PropKey } from '../types';
|
|
2
|
+
import { useElementContext } from '../../contexts/element-context';
|
|
4
3
|
import { getAtomicDynamicTags } from '../sync/get-atomic-dynamic-tags';
|
|
4
|
+
import { PropKey } from '../../types';
|
|
5
|
+
import { isDynamicType } from '../utils';
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const usePropDynamicTags = ( propName: PropKey ) => {
|
|
7
8
|
let categories: string[] = [];
|
|
8
9
|
|
|
9
10
|
const { elementType } = useElementContext();
|
|
@@ -11,9 +12,9 @@ export const useDynamicTagsConfig = ( propName: PropKey ) => {
|
|
|
11
12
|
const propSchema = elementType.propsSchema?.[ propName ];
|
|
12
13
|
|
|
13
14
|
if ( propSchema ) {
|
|
14
|
-
const
|
|
15
|
+
const propDynamicType = propSchema.additional_types.find( isDynamicType );
|
|
15
16
|
|
|
16
|
-
categories =
|
|
17
|
+
categories = propDynamicType?.settings.categories || [];
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicSelectionControl } from './components/dynamic-selection-control';
|
|
2
|
+
import { replaceControl } from '../controls/control-replacement';
|
|
3
|
+
import { isDynamicPropValue } from './utils';
|
|
4
|
+
|
|
5
|
+
export const init = () => {
|
|
6
|
+
replaceControl( {
|
|
7
|
+
component: DynamicSelectionControl,
|
|
8
|
+
condition: ( { value } ) => isDynamicPropValue( value ),
|
|
9
|
+
} );
|
|
10
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ControlItem, PropsSchema, TransformablePropValue } from '../types';
|
|
2
|
+
|
|
3
|
+
export type ExtendedWindow = Window & {
|
|
4
|
+
elementor?: {
|
|
5
|
+
config?: {
|
|
6
|
+
atomicDynamicTags?: {
|
|
7
|
+
tags: DynamicTags;
|
|
8
|
+
groups: Record< DynamicTag[ 'group' ], { title: string } >;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type DynamicTags = Record< DynamicTag[ 'name' ], DynamicTag >;
|
|
15
|
+
|
|
16
|
+
export type DynamicTag = {
|
|
17
|
+
name: string;
|
|
18
|
+
label: string;
|
|
19
|
+
group: string;
|
|
20
|
+
categories: string[];
|
|
21
|
+
atomic_controls: ControlItem[];
|
|
22
|
+
props_schema: PropsSchema;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type DynamicPropType = {
|
|
26
|
+
key: 'dynamic';
|
|
27
|
+
settings: {
|
|
28
|
+
categories: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type DynamicPropValue = TransformablePropValue< { name: string; settings?: Record< string, unknown > } >;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdditionalPropType, PropValue } from '../types';
|
|
2
|
+
import { DynamicPropType } from './types';
|
|
3
|
+
import { isTransformable } from '../props/is-transformable';
|
|
4
|
+
|
|
5
|
+
export const isDynamicType = ( prop: AdditionalPropType ): prop is DynamicPropType => prop.key === 'dynamic';
|
|
6
|
+
|
|
7
|
+
export const isDynamicPropValue = ( prop: PropValue ) => {
|
|
8
|
+
return isTransformable( prop ) && prop.$$type === 'dynamic';
|
|
9
|
+
};
|
package/src/init.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { shouldUseV2Panel } from './sync/should-use-v2-panel';
|
|
|
4
4
|
import { EditingPanelHooks } from './components/editing-panel-hooks';
|
|
5
5
|
import { __registerPanel as registerPanel } from '@elementor/editor-panels';
|
|
6
6
|
import { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';
|
|
7
|
+
import { init as initDynamics } from './dynamics/init';
|
|
7
8
|
|
|
8
9
|
export default function init() {
|
|
9
10
|
registerPanel( panel );
|
|
@@ -13,6 +14,9 @@ export default function init() {
|
|
|
13
14
|
id: 'editing-panel-hooks',
|
|
14
15
|
component: EditingPanelHooks,
|
|
15
16
|
} );
|
|
17
|
+
|
|
18
|
+
// TODO: Move it from here once we have dynamic package.
|
|
19
|
+
initDynamics();
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
const blockV1Panel = () => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
3
|
+
// TODO: Move this file content a shared package.
|
|
4
|
+
|
|
5
|
+
export const transformableSchema = z.object( {
|
|
6
|
+
$$type: z.string(),
|
|
7
|
+
value: z.any(),
|
|
8
|
+
} );
|
|
9
|
+
|
|
10
|
+
export type TransformablePropValue = z.infer< typeof transformableSchema >;
|
|
11
|
+
|
|
12
|
+
export const isTransformable = ( value: unknown ): value is TransformablePropValue => {
|
|
13
|
+
return transformableSchema.safeParse( value ).success;
|
|
14
|
+
};
|
package/src/sync/types.ts
CHANGED
|
@@ -16,22 +16,9 @@ export type ExtendedWindow = Window & {
|
|
|
16
16
|
}
|
|
17
17
|
>;
|
|
18
18
|
getContainer?: ( id: string ) => V1Element;
|
|
19
|
-
config?: {
|
|
20
|
-
atomicDynamicTags?: {
|
|
21
|
-
tags: DynamicTags;
|
|
22
|
-
prop_types_to_dynamic: Record< string, string[] >;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
19
|
};
|
|
26
20
|
};
|
|
27
21
|
|
|
28
|
-
export type DynamicTags = Record< DynamicTag[ 'name' ], DynamicTag >;
|
|
29
|
-
|
|
30
|
-
export type DynamicTag = {
|
|
31
|
-
name: string;
|
|
32
|
-
categories: string[];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
22
|
export type V1Element = {
|
|
36
23
|
model: V1Model< V1ElementModelProps >;
|
|
37
24
|
settings?: V1Model< V1ElementSettingsProps >;
|
package/src/sync/update-style.ts
CHANGED
|
@@ -8,10 +8,10 @@ export type UpdateStyleProps = {
|
|
|
8
8
|
styleDefID?: StyleDefinitionID;
|
|
9
9
|
meta: StyleVariant[ 'meta' ];
|
|
10
10
|
props: Props;
|
|
11
|
-
bind
|
|
11
|
+
bind: PropKey;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const updateStyle = ( { elementID, styleDefID, meta, props, bind
|
|
14
|
+
export const updateStyle = ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {
|
|
15
15
|
const container = getContainer( elementID );
|
|
16
16
|
|
|
17
17
|
runCommand( 'document/atomic-widgets/styles', {
|
package/src/types.ts
CHANGED
|
@@ -34,15 +34,18 @@ export type Control = {
|
|
|
34
34
|
|
|
35
35
|
export type ControlItem = ControlsSection | Control;
|
|
36
36
|
|
|
37
|
-
export type
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
export type AdditionalPropType = {
|
|
38
|
+
key: string;
|
|
39
|
+
settings: Record< string, unknown >;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type PropDefinition = {
|
|
43
|
-
type:
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
type: {
|
|
44
|
+
key: string;
|
|
45
|
+
default: PropValue;
|
|
46
|
+
settings: Record< string, unknown >;
|
|
47
|
+
};
|
|
48
|
+
additional_types: Array< AdditionalPropType >;
|
|
46
49
|
};
|
|
47
50
|
|
|
48
51
|
export type PropsSchema = Record< Control[ 'value' ][ 'bind' ], PropDefinition >;
|