@elementor/editor-editing-panel 4.4.0-beta3 → 4.4.1
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/dist/index.d.mts +33 -21
- package/dist/index.d.ts +33 -21
- package/dist/index.js +682 -360
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +554 -224
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -25
- package/src/components/css-classes/css-class-menu.tsx +4 -1
- package/src/components/css-classes/css-class-selector.tsx +3 -0
- package/src/components/custom-css-header-location.tsx +11 -0
- package/src/components/section.tsx +19 -1
- package/src/components/style-section-header-location.tsx +29 -0
- package/src/components/style-tab-header-location.tsx +12 -0
- package/src/components/style-tab-section.tsx +6 -0
- package/src/components/style-tab.tsx +3 -0
- package/src/controls-registry/controls-registry.tsx +1 -1
- package/src/controls-registry/element-controls/menu-items-control/menu-items-control.tsx +188 -0
- package/src/controls-registry/element-controls/menu-items-control/use-actions.ts +126 -0
- package/src/controls-registry/element-controls/menu-items-control/use-entry-item.ts +33 -0
- package/src/controls-registry/element-controls/registry.ts +2 -0
- package/src/hooks/use-broadcast-style-state.ts +20 -0
- package/src/index.ts +7 -0
- package/src/init.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,32 +39,32 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "4.4.
|
|
43
|
-
"@elementor/editor-canvas": "4.4.
|
|
44
|
-
"@elementor/editor-controls": "4.4.
|
|
45
|
-
"@elementor/editor-current-user": "4.4.
|
|
46
|
-
"@elementor/editor-documents": "4.4.
|
|
47
|
-
"@elementor/editor-elements": "4.4.
|
|
48
|
-
"@elementor/editor-interactions": "4.4.
|
|
49
|
-
"@elementor/editor-notifications": "4.4.
|
|
50
|
-
"@elementor/editor-panels": "4.4.
|
|
51
|
-
"@elementor/editor-props": "4.4.
|
|
52
|
-
"@elementor/editor-responsive": "4.4.
|
|
53
|
-
"@elementor/editor-styles": "4.4.
|
|
54
|
-
"@elementor/editor-styles-repository": "4.4.
|
|
55
|
-
"@elementor/editor-ui": "4.4.
|
|
56
|
-
"@elementor/editor-v1-adapters": "4.4.
|
|
57
|
-
"@elementor/http-client": "4.4.
|
|
42
|
+
"@elementor/editor": "4.4.1",
|
|
43
|
+
"@elementor/editor-canvas": "4.4.1",
|
|
44
|
+
"@elementor/editor-controls": "4.4.1",
|
|
45
|
+
"@elementor/editor-current-user": "4.4.1",
|
|
46
|
+
"@elementor/editor-documents": "4.4.1",
|
|
47
|
+
"@elementor/editor-elements": "4.4.1",
|
|
48
|
+
"@elementor/editor-interactions": "4.4.1",
|
|
49
|
+
"@elementor/editor-notifications": "4.4.1",
|
|
50
|
+
"@elementor/editor-panels": "4.4.1",
|
|
51
|
+
"@elementor/editor-props": "4.4.1",
|
|
52
|
+
"@elementor/editor-responsive": "4.4.1",
|
|
53
|
+
"@elementor/editor-styles": "4.4.1",
|
|
54
|
+
"@elementor/editor-styles-repository": "4.4.1",
|
|
55
|
+
"@elementor/editor-ui": "4.4.1",
|
|
56
|
+
"@elementor/editor-v1-adapters": "4.4.1",
|
|
57
|
+
"@elementor/http-client": "4.4.1",
|
|
58
58
|
"@elementor/icons": "~1.78.1",
|
|
59
|
-
"@elementor/editor-variables": "4.4.
|
|
60
|
-
"@elementor/locations": "4.4.
|
|
61
|
-
"@elementor/menus": "4.4.
|
|
62
|
-
"@elementor/query": "4.4.
|
|
63
|
-
"@elementor/schema": "4.4.
|
|
64
|
-
"@elementor/session": "4.4.
|
|
59
|
+
"@elementor/editor-variables": "4.4.1",
|
|
60
|
+
"@elementor/locations": "4.4.1",
|
|
61
|
+
"@elementor/menus": "4.4.1",
|
|
62
|
+
"@elementor/query": "4.4.1",
|
|
63
|
+
"@elementor/schema": "4.4.1",
|
|
64
|
+
"@elementor/session": "4.4.1",
|
|
65
65
|
"@elementor/ui": "1.41.4",
|
|
66
|
-
"@elementor/utils": "4.4.
|
|
67
|
-
"@elementor/wp-media": "4.4.
|
|
66
|
+
"@elementor/utils": "4.4.1",
|
|
67
|
+
"@elementor/wp-media": "4.4.1",
|
|
68
68
|
"@wordpress/i18n": "^5.13.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
@@ -130,6 +130,9 @@ const CLASS_STATES_MAP: Record< string, { label: string } > = {
|
|
|
130
130
|
disabled: {
|
|
131
131
|
label: __( 'disabled', 'elementor' ),
|
|
132
132
|
},
|
|
133
|
+
current: {
|
|
134
|
+
label: __( 'current', 'elementor' ),
|
|
135
|
+
},
|
|
133
136
|
};
|
|
134
137
|
|
|
135
138
|
export function useElementStates() {
|
|
@@ -140,7 +143,7 @@ export function useElementStates() {
|
|
|
140
143
|
const elementStates = styleStates.map( ( { value, name } ) => ( {
|
|
141
144
|
key: value,
|
|
142
145
|
value,
|
|
143
|
-
label: CLASS_STATES_MAP[
|
|
146
|
+
label: CLASS_STATES_MAP[ name ]?.label ?? name,
|
|
144
147
|
} ) );
|
|
145
148
|
|
|
146
149
|
return {
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
type ValidationEvent,
|
|
39
39
|
type ValidationResult,
|
|
40
40
|
} from '../creatable-autocomplete';
|
|
41
|
+
import { StyleTabHeaderSlot } from '../style-tab-header-location';
|
|
41
42
|
import { CssClassItem } from './css-class-item';
|
|
42
43
|
import { MissingClassesAlert } from './missing-classes-alert';
|
|
43
44
|
import {
|
|
@@ -82,6 +83,7 @@ export const { Slot: ClassSelectorActionsSlot, inject: injectIntoClassSelectorAc
|
|
|
82
83
|
*/
|
|
83
84
|
|
|
84
85
|
export function CssClassSelector() {
|
|
86
|
+
const { element } = useElement();
|
|
85
87
|
const options = useOptions();
|
|
86
88
|
|
|
87
89
|
const { id: activeId, setId: setActiveId } = useStyle();
|
|
@@ -117,6 +119,7 @@ export function CssClassSelector() {
|
|
|
117
119
|
{ __( 'Classes', 'elementor' ) }
|
|
118
120
|
</FormLabel>
|
|
119
121
|
<Stack direction="row" gap={ 1 }>
|
|
122
|
+
<StyleTabHeaderSlot elementId={ element.id } />
|
|
120
123
|
<ClassSelectorActionsSlot />
|
|
121
124
|
</Stack>
|
|
122
125
|
</Stack>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLocation } from '@elementor/locations';
|
|
2
|
+
|
|
3
|
+
export type CustomCssHeaderProps = {
|
|
4
|
+
elementId: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const {
|
|
8
|
+
Slot: CustomCssHeaderSlot,
|
|
9
|
+
inject: injectIntoCustomCssHeader,
|
|
10
|
+
useInjections: useCustomCssHeaderInjections,
|
|
11
|
+
} = createLocation< CustomCssHeaderProps >();
|
|
@@ -9,11 +9,20 @@ type Props = PropsWithChildren< {
|
|
|
9
9
|
title: string;
|
|
10
10
|
defaultExpanded?: boolean;
|
|
11
11
|
titleEnd?: CollapsibleValue< ReactNode | string >;
|
|
12
|
+
titleActions?: ReactNode;
|
|
12
13
|
unmountOnExit?: boolean;
|
|
13
14
|
action?: { component: ReactNode; onClick: () => void };
|
|
14
15
|
} >;
|
|
15
16
|
|
|
16
|
-
export function Section( {
|
|
17
|
+
export function Section( {
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
defaultExpanded = false,
|
|
21
|
+
titleEnd,
|
|
22
|
+
titleActions,
|
|
23
|
+
unmountOnExit = true,
|
|
24
|
+
action,
|
|
25
|
+
}: Props ) {
|
|
17
26
|
const [ isOpen, setIsOpen ] = useStateByElement( title, !! defaultExpanded );
|
|
18
27
|
const ref = useRef< HTMLElement >( null );
|
|
19
28
|
const isDisabled = !! action;
|
|
@@ -46,6 +55,15 @@ export function Section( { title, children, defaultExpanded = false, titleEnd, u
|
|
|
46
55
|
sx={ { flexGrow: 0, flexShrink: 1, marginInlineEnd: 1 } }
|
|
47
56
|
/>
|
|
48
57
|
{ getCollapsibleValue( titleEnd, isOpen ) }
|
|
58
|
+
{ titleActions && (
|
|
59
|
+
<Stack
|
|
60
|
+
direction="row"
|
|
61
|
+
alignItems="center"
|
|
62
|
+
onClick={ ( event: React.MouseEvent ) => event.stopPropagation() }
|
|
63
|
+
>
|
|
64
|
+
{ titleActions }
|
|
65
|
+
</Stack>
|
|
66
|
+
) }
|
|
49
67
|
</Stack>
|
|
50
68
|
{ action?.component }
|
|
51
69
|
<CollapseIcon
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ComponentType, createElement } from 'react';
|
|
2
|
+
import { type ElementID } from '@elementor/editor-elements';
|
|
3
|
+
import { createLocation, type InjectArgs } from '@elementor/locations';
|
|
4
|
+
|
|
5
|
+
export type StyleSectionHeaderProps = {
|
|
6
|
+
elementId: ElementID;
|
|
7
|
+
sectionName: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const { Slot: StyleSectionHeaderSlot, inject: injectStyleSectionHeader } = createLocation< StyleSectionHeaderProps >();
|
|
11
|
+
|
|
12
|
+
type StyleSectionHeaderInjectArgs = Pick< InjectArgs< StyleSectionHeaderProps >, 'id' | 'component' > & {
|
|
13
|
+
sections?: string[];
|
|
14
|
+
options?: InjectArgs< StyleSectionHeaderProps >[ 'options' ];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const injectIntoStyleSectionHeader = ( { id, component, sections, options }: StyleSectionHeaderInjectArgs ) => {
|
|
18
|
+
const filteredComponent: ComponentType< StyleSectionHeaderProps > = ( props ) => {
|
|
19
|
+
if ( sections && ! sections.includes( props.sectionName ) ) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return createElement( component, props );
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
injectStyleSectionHeader( { id, component: filteredComponent, options } );
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { StyleSectionHeaderSlot };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ElementID } from '@elementor/editor-elements';
|
|
2
|
+
import { createLocation } from '@elementor/locations';
|
|
3
|
+
|
|
4
|
+
export type StyleTabHeaderProps = {
|
|
5
|
+
elementId: ElementID;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const {
|
|
9
|
+
Slot: StyleTabHeaderSlot,
|
|
10
|
+
inject: injectIntoStyleTabHeader,
|
|
11
|
+
useInjections: useStyleTabHeaderInjections,
|
|
12
|
+
} = createLocation< StyleTabHeaderProps >();
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
+
import { useElement } from '../contexts/element-context';
|
|
4
5
|
import { useDefaultPanelSettings } from '../hooks/use-default-panel-settings';
|
|
5
6
|
import { Section } from './section';
|
|
7
|
+
import { StyleSectionHeaderSlot } from './style-section-header-location';
|
|
6
8
|
import { getStylesInheritanceIndicators } from './style-tab-collapsible-content';
|
|
7
9
|
|
|
8
10
|
type SectionType = {
|
|
@@ -16,6 +18,7 @@ type Props = { section: SectionType; fields?: string[]; unmountOnExit?: boolean
|
|
|
16
18
|
|
|
17
19
|
export const StyleTabSection = ( { section, fields = [], unmountOnExit = true }: Props ) => {
|
|
18
20
|
const { component, name, title, action } = section;
|
|
21
|
+
const { element } = useElement();
|
|
19
22
|
const tabDefaults = useDefaultPanelSettings();
|
|
20
23
|
const SectionComponent = component || ( () => <></> );
|
|
21
24
|
const isExpanded = tabDefaults.defaultSectionsExpanded.style?.includes( name );
|
|
@@ -25,6 +28,9 @@ export const StyleTabSection = ( { section, fields = [], unmountOnExit = true }:
|
|
|
25
28
|
title={ title }
|
|
26
29
|
defaultExpanded={ isExpanded }
|
|
27
30
|
titleEnd={ getStylesInheritanceIndicators( fields ) }
|
|
31
|
+
titleActions={
|
|
32
|
+
element ? <StyleSectionHeaderSlot elementId={ element.id } sectionName={ name } /> : undefined
|
|
33
|
+
}
|
|
28
34
|
unmountOnExit={ unmountOnExit }
|
|
29
35
|
action={ action }
|
|
30
36
|
>
|
|
@@ -13,6 +13,7 @@ import { useScrollDirection } from '../contexts/scroll-context';
|
|
|
13
13
|
import { StyleProvider } from '../contexts/style-context';
|
|
14
14
|
import { StyleInheritanceProvider } from '../contexts/styles-inheritance-context';
|
|
15
15
|
import { useActiveStyleDefId } from '../hooks/use-active-style-def-id';
|
|
16
|
+
import { useBroadcastStyleState } from '../hooks/use-broadcast-style-state';
|
|
16
17
|
import { CssClassSelector } from './css-classes/css-class-selector';
|
|
17
18
|
import { SectionsList } from './sections-list';
|
|
18
19
|
import { StyleSections } from './style-sections';
|
|
@@ -35,6 +36,8 @@ export const StyleTab = () => {
|
|
|
35
36
|
const [ activeStyleState, setActiveStyleState ] = useState< StyleDefinitionState | null >( null );
|
|
36
37
|
const breakpoint = useActiveBreakpoint();
|
|
37
38
|
|
|
39
|
+
useBroadcastStyleState( activeStyleState );
|
|
40
|
+
|
|
38
41
|
if ( ! currentClassesProp ) {
|
|
39
42
|
return null;
|
|
40
43
|
}
|
|
@@ -87,7 +87,7 @@ const controlTypes = {
|
|
|
87
87
|
toggle: { component: ToggleControl, layout: 'full', propTypeUtil: stringPropTypeUtil },
|
|
88
88
|
'date-time': { component: DateTimeControl, layout: 'full', propTypeUtil: DateTimePropTypeUtil },
|
|
89
89
|
video: { component: VideoMediaControl, layout: 'full', propTypeUtil: videoSrcPropTypeUtil },
|
|
90
|
-
'inline-editing': { component: InlineEditingControl, layout: '
|
|
90
|
+
'inline-editing': { component: InlineEditingControl, layout: 'custom', propTypeUtil: escapedHtmlPropTypeUtil },
|
|
91
91
|
email: { component: EmailFormActionControl, layout: 'custom', propTypeUtil: emailsPropTypeUtil },
|
|
92
92
|
'date-range': {
|
|
93
93
|
component: DateRangeControl,
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { ControlFormLabel, Repeater, type RepeaterItem, type SetRepeaterValuesMeta } from '@elementor/editor-controls';
|
|
4
|
+
import {
|
|
5
|
+
type Control,
|
|
6
|
+
type ControlItem,
|
|
7
|
+
getElementType,
|
|
8
|
+
updateElementEditorSettings,
|
|
9
|
+
useElementChildren,
|
|
10
|
+
useElementEditorSettings,
|
|
11
|
+
type V1Element,
|
|
12
|
+
} from '@elementor/editor-elements';
|
|
13
|
+
import { type CreateOptions } from '@elementor/editor-props';
|
|
14
|
+
import { SessionStorageProvider } from '@elementor/session';
|
|
15
|
+
import { Stack, TextField } from '@elementor/ui';
|
|
16
|
+
import { __ } from '@wordpress/i18n';
|
|
17
|
+
|
|
18
|
+
import { SettingsControl } from '../../../components/settings-control';
|
|
19
|
+
import { ElementProvider, useElement } from '../../../contexts/element-context';
|
|
20
|
+
import { getElementByType } from '../get-element-by-type';
|
|
21
|
+
import {
|
|
22
|
+
MENU_ENTRY_ELEMENT_TYPE,
|
|
23
|
+
MENU_ITEM_ELEMENT_TYPE,
|
|
24
|
+
MENU_ITEMS_ELEMENT_TYPE,
|
|
25
|
+
type MenuItem,
|
|
26
|
+
useActions,
|
|
27
|
+
} from './use-actions';
|
|
28
|
+
import { useEntryItem } from './use-entry-item';
|
|
29
|
+
|
|
30
|
+
const LINK_BIND = 'link';
|
|
31
|
+
|
|
32
|
+
export const MenuItemsControl = ( { label }: { label: string } ) => {
|
|
33
|
+
const { element } = useElement();
|
|
34
|
+
const { addItem, duplicateItem, moveItem, removeItem } = useActions();
|
|
35
|
+
|
|
36
|
+
const { [ MENU_ENTRY_ELEMENT_TYPE ]: entries } = useElementChildren( element.id, {
|
|
37
|
+
[ MENU_ITEMS_ELEMENT_TYPE ]: MENU_ENTRY_ELEMENT_TYPE,
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
const menuItems = getElementByType( element.id, MENU_ITEMS_ELEMENT_TYPE ) as V1Element | null;
|
|
41
|
+
|
|
42
|
+
const repeaterValues: RepeaterItem< MenuItem >[] = entries.map( ( entry, index ) => ( {
|
|
43
|
+
id: entry.id,
|
|
44
|
+
title: entry.editorSettings?.title,
|
|
45
|
+
index,
|
|
46
|
+
} ) );
|
|
47
|
+
|
|
48
|
+
const setValue = (
|
|
49
|
+
_newValues: RepeaterItem< MenuItem >[],
|
|
50
|
+
_options: CreateOptions,
|
|
51
|
+
meta?: SetRepeaterValuesMeta< RepeaterItem< MenuItem > >
|
|
52
|
+
) => {
|
|
53
|
+
if ( ! menuItems ) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if ( meta?.action?.type === 'add' ) {
|
|
58
|
+
return addItem( {
|
|
59
|
+
menuItemsId: menuItems.id,
|
|
60
|
+
items: meta.action.payload,
|
|
61
|
+
} );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ( meta?.action?.type === 'remove' ) {
|
|
65
|
+
return removeItem( { menuItemsId: menuItems.id, items: meta.action.payload } );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ( meta?.action?.type === 'duplicate' ) {
|
|
69
|
+
return duplicateItem( { items: meta.action.payload } );
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( meta?.action?.type === 'reorder' ) {
|
|
73
|
+
const { from, to } = meta.action.payload;
|
|
74
|
+
|
|
75
|
+
return moveItem( {
|
|
76
|
+
menuItemsId: menuItems.id,
|
|
77
|
+
movedElementId: entries[ from ].id,
|
|
78
|
+
toIndex: to,
|
|
79
|
+
} );
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Repeater
|
|
85
|
+
showToggle={ false }
|
|
86
|
+
values={ repeaterValues }
|
|
87
|
+
setValues={ setValue }
|
|
88
|
+
showRemove={ repeaterValues.length > 1 }
|
|
89
|
+
label={ label }
|
|
90
|
+
adornment={ () => null }
|
|
91
|
+
itemSettings={ {
|
|
92
|
+
getId: ( { item } ) => item.id,
|
|
93
|
+
initialValues: { id: '', title: __( 'Menu item', 'elementor' ) },
|
|
94
|
+
Label: ItemLabel,
|
|
95
|
+
Content: ItemContent,
|
|
96
|
+
Icon: () => null,
|
|
97
|
+
} }
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const ItemLabel = ( { value }: { value: MenuItem } ) => (
|
|
103
|
+
<Stack sx={ { minHeight: 20 } } direction="row" alignItems="center" gap={ 1.5 }>
|
|
104
|
+
{ value.id ? (
|
|
105
|
+
<EntryLabel elementId={ value.id } fallbackTitle={ value.title } />
|
|
106
|
+
) : (
|
|
107
|
+
<span>{ value?.title }</span>
|
|
108
|
+
) }
|
|
109
|
+
</Stack>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const EntryLabel = ( { elementId, fallbackTitle }: { elementId: string; fallbackTitle?: string } ) => {
|
|
113
|
+
const editorSettings = useElementEditorSettings( elementId );
|
|
114
|
+
|
|
115
|
+
return <span>{ editorSettings?.title ?? fallbackTitle ?? '' }</span>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const ItemContent = ( { value }: { value: MenuItem } ) => {
|
|
119
|
+
if ( ! value.id ) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<Stack p={ 2 } gap={ 1.5 }>
|
|
125
|
+
<ItemNameControl elementId={ value.id } />
|
|
126
|
+
<ItemLinkControl entryId={ value.id } />
|
|
127
|
+
</Stack>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const ItemNameControl = ( { elementId }: { elementId: string } ) => {
|
|
132
|
+
const editorSettings = useElementEditorSettings( elementId );
|
|
133
|
+
const inputId = useId();
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Stack gap={ 1 }>
|
|
137
|
+
<ControlFormLabel htmlFor={ inputId }>{ __( 'Item name', 'elementor' ) }</ControlFormLabel>
|
|
138
|
+
<TextField
|
|
139
|
+
id={ inputId }
|
|
140
|
+
size="tiny"
|
|
141
|
+
value={ editorSettings?.title ?? '' }
|
|
142
|
+
onChange={ ( { target }: React.ChangeEvent< HTMLInputElement > ) => {
|
|
143
|
+
updateElementEditorSettings( { elementId, settings: { title: target.value } } );
|
|
144
|
+
} }
|
|
145
|
+
/>
|
|
146
|
+
</Stack>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const ItemLinkControl = ( { entryId }: { entryId: string } ) => {
|
|
151
|
+
const { itemId, settings } = useEntryItem( entryId );
|
|
152
|
+
const elementType = itemId ? getElementType( MENU_ITEM_ELEMENT_TYPE ) : null;
|
|
153
|
+
const linkControl = elementType ? findControlByBind( elementType.controls, LINK_BIND ) : null;
|
|
154
|
+
|
|
155
|
+
if ( ! itemId || ! elementType || ! linkControl ) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<ElementProvider
|
|
161
|
+
element={ { id: itemId, type: MENU_ITEM_ELEMENT_TYPE } }
|
|
162
|
+
elementType={ elementType }
|
|
163
|
+
settings={ settings }
|
|
164
|
+
>
|
|
165
|
+
<SessionStorageProvider prefix={ itemId }>
|
|
166
|
+
<SettingsControl control={ linkControl } />
|
|
167
|
+
</SessionStorageProvider>
|
|
168
|
+
</ElementProvider>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const findControlByBind = ( items: ControlItem[], bind: string ): Control | null => {
|
|
173
|
+
for ( const item of items ) {
|
|
174
|
+
if ( item.type === 'section' ) {
|
|
175
|
+
const found = findControlByBind( item.value.items, bind );
|
|
176
|
+
|
|
177
|
+
if ( found ) {
|
|
178
|
+
return found;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if ( item.type === 'control' && item.value.bind === bind ) {
|
|
183
|
+
return item;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return null;
|
|
188
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type ItemsActionPayload } from '@elementor/editor-controls';
|
|
2
|
+
import {
|
|
3
|
+
type CreateElementParams,
|
|
4
|
+
createElements,
|
|
5
|
+
duplicateElements,
|
|
6
|
+
generateElementId,
|
|
7
|
+
getContainer,
|
|
8
|
+
moveElements,
|
|
9
|
+
removeElements,
|
|
10
|
+
type V1ElementData,
|
|
11
|
+
} from '@elementor/editor-elements';
|
|
12
|
+
import { escapedHtmlPropTypeUtil } from '@elementor/editor-props';
|
|
13
|
+
import { __ } from '@wordpress/i18n';
|
|
14
|
+
|
|
15
|
+
export type MenuItem = {
|
|
16
|
+
id: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const MENU_ITEMS_ELEMENT_TYPE = 'e-menu-items';
|
|
21
|
+
export const MENU_ENTRY_ELEMENT_TYPE = 'e-menu-entry';
|
|
22
|
+
export const MENU_ITEM_ELEMENT_TYPE = 'e-menu-item';
|
|
23
|
+
const MIN_ENTRIES = 1;
|
|
24
|
+
const PARAGRAPH_WIDGET_TYPE = 'e-paragraph';
|
|
25
|
+
|
|
26
|
+
const getEntryTitle = () => __( 'Menu item', 'elementor' );
|
|
27
|
+
|
|
28
|
+
const buildEntryModel = ( title: string ): V1ElementData => ( {
|
|
29
|
+
elType: MENU_ENTRY_ELEMENT_TYPE,
|
|
30
|
+
id: generateElementId(),
|
|
31
|
+
editor_settings: { title },
|
|
32
|
+
elements: [
|
|
33
|
+
{
|
|
34
|
+
elType: MENU_ITEM_ELEMENT_TYPE,
|
|
35
|
+
id: generateElementId(),
|
|
36
|
+
elements: [
|
|
37
|
+
{
|
|
38
|
+
elType: 'widget',
|
|
39
|
+
widgetType: PARAGRAPH_WIDGET_TYPE,
|
|
40
|
+
id: generateElementId(),
|
|
41
|
+
elements: [],
|
|
42
|
+
settings: {
|
|
43
|
+
paragraph: escapedHtmlPropTypeUtil.create( title ),
|
|
44
|
+
tag: { $$type: 'string', value: 'span' },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
} );
|
|
51
|
+
|
|
52
|
+
export const useActions = () => {
|
|
53
|
+
const addItem = ( { menuItemsId, items }: { menuItemsId: string; items: ItemsActionPayload< MenuItem > } ) => {
|
|
54
|
+
const menuItems = getContainer( menuItemsId );
|
|
55
|
+
|
|
56
|
+
if ( ! menuItems ) {
|
|
57
|
+
throw new Error( 'Menu items container not found' );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
items.forEach( () => {
|
|
61
|
+
createElements( {
|
|
62
|
+
title: __( 'Menu', 'elementor' ),
|
|
63
|
+
elements: [
|
|
64
|
+
{
|
|
65
|
+
container: menuItems,
|
|
66
|
+
model: buildEntryModel( getEntryTitle() ) as CreateElementParams[ 'model' ],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
} );
|
|
70
|
+
} );
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const removeItem = ( { menuItemsId, items }: { menuItemsId: string; items: ItemsActionPayload< MenuItem > } ) => {
|
|
74
|
+
const entriesCount =
|
|
75
|
+
getContainer( menuItemsId )?.children?.filter(
|
|
76
|
+
( child ) => child.model.get( 'elType' ) === MENU_ENTRY_ELEMENT_TYPE
|
|
77
|
+
).length ?? 0;
|
|
78
|
+
const removableCount = Math.max( 0, Math.min( items.length, entriesCount - MIN_ENTRIES ) );
|
|
79
|
+
|
|
80
|
+
if ( removableCount === 0 ) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
removeElements( {
|
|
85
|
+
title: __( 'Menu', 'elementor' ),
|
|
86
|
+
elementIds: items.slice( 0, removableCount ).map( ( { item } ) => item.id ),
|
|
87
|
+
} );
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const duplicateItem = ( { items }: { items: ItemsActionPayload< MenuItem > } ) => {
|
|
91
|
+
duplicateElements( {
|
|
92
|
+
title: __( 'Duplicate Menu item', 'elementor' ),
|
|
93
|
+
elementIds: items.map( ( { item } ) => item.id ),
|
|
94
|
+
} );
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const moveItem = ( {
|
|
98
|
+
menuItemsId,
|
|
99
|
+
movedElementId,
|
|
100
|
+
toIndex,
|
|
101
|
+
}: {
|
|
102
|
+
menuItemsId: string;
|
|
103
|
+
movedElementId: string;
|
|
104
|
+
toIndex: number;
|
|
105
|
+
} ) => {
|
|
106
|
+
const menuItems = getContainer( menuItemsId );
|
|
107
|
+
const movedElement = getContainer( movedElementId );
|
|
108
|
+
|
|
109
|
+
if ( ! menuItems || ! movedElement ) {
|
|
110
|
+
throw new Error( 'Menu item or container not found' );
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
moveElements( {
|
|
114
|
+
title: __( 'Reorder Menu items', 'elementor' ),
|
|
115
|
+
moves: [
|
|
116
|
+
{
|
|
117
|
+
element: movedElement,
|
|
118
|
+
targetContainer: menuItems,
|
|
119
|
+
options: { at: toIndex },
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
} );
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return { addItem, removeItem, duplicateItem, moveItem };
|
|
126
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ElementID, getContainer, getElementSettings, getElementType } from '@elementor/editor-elements';
|
|
2
|
+
import { type AnyTransformable } from '@elementor/editor-props';
|
|
3
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
4
|
+
|
|
5
|
+
import { MENU_ITEM_ELEMENT_TYPE } from './use-actions';
|
|
6
|
+
|
|
7
|
+
type EntryItem = {
|
|
8
|
+
itemId: ElementID | null;
|
|
9
|
+
settings: Record< string, AnyTransformable | null >;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useEntryItem = ( entryId: ElementID ): EntryItem => {
|
|
13
|
+
return useListenTo(
|
|
14
|
+
[ commandEndEvent( 'document/elements/set-settings' ), commandEndEvent( 'document/elements/settings' ) ],
|
|
15
|
+
() => {
|
|
16
|
+
const item = getContainer( entryId )?.children?.find(
|
|
17
|
+
( child ) => child.model.get( 'elType' ) === MENU_ITEM_ELEMENT_TYPE
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
itemId: item?.id ?? null,
|
|
22
|
+
settings: item ? getEntrySettings( item.id ) : {},
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
[ entryId ]
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getEntrySettings = ( itemId: ElementID ): EntryItem[ 'settings' ] => {
|
|
30
|
+
const propsSchema = getElementType( MENU_ITEM_ELEMENT_TYPE )?.propsSchema ?? {};
|
|
31
|
+
|
|
32
|
+
return getElementSettings< AnyTransformable >( itemId, Object.keys( propsSchema ) );
|
|
33
|
+
};
|
|
@@ -3,10 +3,12 @@ import { type ControlComponent } from '@elementor/editor-controls';
|
|
|
3
3
|
import { type ControlRegistry, controlsRegistry } from '../controls-registry';
|
|
4
4
|
import { AccordionItemsControl } from './accordion-items-control/accordion-items-control';
|
|
5
5
|
import { ListItemsControl } from './list-items-control/list-items-control';
|
|
6
|
+
import { MenuItemsControl } from './menu-items-control/menu-items-control';
|
|
6
7
|
import { TabsControl } from './tabs-control/tabs-control';
|
|
7
8
|
|
|
8
9
|
const controlTypes = {
|
|
9
10
|
'list-items': { component: ListItemsControl as ControlComponent, layout: 'full' },
|
|
11
|
+
'menu-items': { component: MenuItemsControl as ControlComponent, layout: 'full' },
|
|
10
12
|
tabs: { component: TabsControl as ControlComponent, layout: 'full' },
|
|
11
13
|
'accordion-items': { component: AccordionItemsControl as ControlComponent, layout: 'full' },
|
|
12
14
|
} as const satisfies ControlRegistry;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { type StyleDefinitionState } from '@elementor/editor-styles';
|
|
3
|
+
|
|
4
|
+
import { useElement } from '../contexts/element-context';
|
|
5
|
+
|
|
6
|
+
export const STYLE_STATE_EVENT = 'elementor/editor/style-state/change';
|
|
7
|
+
|
|
8
|
+
function broadcast( id: string, state: StyleDefinitionState | null ) {
|
|
9
|
+
window.dispatchEvent( new CustomEvent( STYLE_STATE_EVENT, { detail: { id, state } } ) );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useBroadcastStyleState( state: StyleDefinitionState | null ) {
|
|
13
|
+
const { element } = useElement();
|
|
14
|
+
|
|
15
|
+
useEffect( () => {
|
|
16
|
+
broadcast( element.id, state );
|
|
17
|
+
|
|
18
|
+
return () => broadcast( element.id, null );
|
|
19
|
+
}, [ element.id, state ] );
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,13 @@ export { PseudoStateMenuItems } from './components/style-states/pseudo-state-men
|
|
|
28
28
|
export { usePseudoStates } from './components/style-states/use-pseudo-states';
|
|
29
29
|
export { injectIntoGridFields } from './components/style-sections/layout-section/layout-section';
|
|
30
30
|
export { StyleTabSection } from './components/style-tab-section';
|
|
31
|
+
export {
|
|
32
|
+
CustomCssHeaderSlot,
|
|
33
|
+
injectIntoCustomCssHeader,
|
|
34
|
+
type CustomCssHeaderProps,
|
|
35
|
+
} from './components/custom-css-header-location';
|
|
36
|
+
export { injectIntoStyleSectionHeader, type StyleSectionHeaderProps } from './components/style-section-header-location';
|
|
37
|
+
export { injectIntoStyleTabHeader, type StyleTabHeaderProps } from './components/style-tab-header-location';
|
|
31
38
|
export { ClassesPropProvider, useClassesProp } from './contexts/classes-prop-context';
|
|
32
39
|
export { ElementProvider, useElement } from './contexts/element-context';
|
|
33
40
|
export { StyleProvider, useStyle } from './contexts/style-context';
|
package/src/init.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { injectIntoLogic } from '@elementor/editor';
|
|
2
|
+
import { init as initEditorControls } from '@elementor/editor-controls';
|
|
2
3
|
import { registerPanel } from '@elementor/editor-panels';
|
|
3
4
|
import { blockCommand } from '@elementor/editor-v1-adapters';
|
|
4
5
|
|
|
@@ -12,6 +13,8 @@ import { init as initStylesInheritance } from './styles-inheritance/init';
|
|
|
12
13
|
import { isAtomicWidgetSelected } from './sync/is-atomic-widget-selected';
|
|
13
14
|
|
|
14
15
|
export function init() {
|
|
16
|
+
initEditorControls();
|
|
17
|
+
|
|
15
18
|
registerPanel( panel );
|
|
16
19
|
blockV1Panel();
|
|
17
20
|
|