@elementor/editor-editing-panel 4.5.0-1175 → 4.5.0-1177
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.js +458 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +380 -190
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -25
- package/src/controls-registry/element-controls/menu-items-control/menu-items-control.tsx +133 -0
- package/src/controls-registry/element-controls/menu-items-control/use-actions.ts +115 -0
- package/src/controls-registry/element-controls/registry.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "4.5.0-
|
|
3
|
+
"version": "4.5.0-1177",
|
|
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.5.0-
|
|
43
|
-
"@elementor/editor-canvas": "4.5.0-
|
|
44
|
-
"@elementor/editor-controls": "4.5.0-
|
|
45
|
-
"@elementor/editor-current-user": "4.5.0-
|
|
46
|
-
"@elementor/editor-documents": "4.5.0-
|
|
47
|
-
"@elementor/editor-elements": "4.5.0-
|
|
48
|
-
"@elementor/editor-interactions": "4.5.0-
|
|
49
|
-
"@elementor/editor-notifications": "4.5.0-
|
|
50
|
-
"@elementor/editor-panels": "4.5.0-
|
|
51
|
-
"@elementor/editor-props": "4.5.0-
|
|
52
|
-
"@elementor/editor-responsive": "4.5.0-
|
|
53
|
-
"@elementor/editor-styles": "4.5.0-
|
|
54
|
-
"@elementor/editor-styles-repository": "4.5.0-
|
|
55
|
-
"@elementor/editor-ui": "4.5.0-
|
|
56
|
-
"@elementor/editor-v1-adapters": "4.5.0-
|
|
57
|
-
"@elementor/http-client": "4.5.0-
|
|
42
|
+
"@elementor/editor": "4.5.0-1177",
|
|
43
|
+
"@elementor/editor-canvas": "4.5.0-1177",
|
|
44
|
+
"@elementor/editor-controls": "4.5.0-1177",
|
|
45
|
+
"@elementor/editor-current-user": "4.5.0-1177",
|
|
46
|
+
"@elementor/editor-documents": "4.5.0-1177",
|
|
47
|
+
"@elementor/editor-elements": "4.5.0-1177",
|
|
48
|
+
"@elementor/editor-interactions": "4.5.0-1177",
|
|
49
|
+
"@elementor/editor-notifications": "4.5.0-1177",
|
|
50
|
+
"@elementor/editor-panels": "4.5.0-1177",
|
|
51
|
+
"@elementor/editor-props": "4.5.0-1177",
|
|
52
|
+
"@elementor/editor-responsive": "4.5.0-1177",
|
|
53
|
+
"@elementor/editor-styles": "4.5.0-1177",
|
|
54
|
+
"@elementor/editor-styles-repository": "4.5.0-1177",
|
|
55
|
+
"@elementor/editor-ui": "4.5.0-1177",
|
|
56
|
+
"@elementor/editor-v1-adapters": "4.5.0-1177",
|
|
57
|
+
"@elementor/http-client": "4.5.0-1177",
|
|
58
58
|
"@elementor/icons": "~1.78.1",
|
|
59
|
-
"@elementor/editor-variables": "4.5.0-
|
|
60
|
-
"@elementor/locations": "4.5.0-
|
|
61
|
-
"@elementor/menus": "4.5.0-
|
|
62
|
-
"@elementor/query": "4.5.0-
|
|
63
|
-
"@elementor/schema": "4.5.0-
|
|
64
|
-
"@elementor/session": "4.5.0-
|
|
59
|
+
"@elementor/editor-variables": "4.5.0-1177",
|
|
60
|
+
"@elementor/locations": "4.5.0-1177",
|
|
61
|
+
"@elementor/menus": "4.5.0-1177",
|
|
62
|
+
"@elementor/query": "4.5.0-1177",
|
|
63
|
+
"@elementor/schema": "4.5.0-1177",
|
|
64
|
+
"@elementor/session": "4.5.0-1177",
|
|
65
65
|
"@elementor/ui": "1.41.4",
|
|
66
|
-
"@elementor/utils": "4.5.0-
|
|
67
|
-
"@elementor/wp-media": "4.5.0-
|
|
66
|
+
"@elementor/utils": "4.5.0-1177",
|
|
67
|
+
"@elementor/wp-media": "4.5.0-1177",
|
|
68
68
|
"@wordpress/i18n": "^5.13.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
updateElementEditorSettings,
|
|
6
|
+
useElementChildren,
|
|
7
|
+
useElementEditorSettings,
|
|
8
|
+
type V1Element,
|
|
9
|
+
} from '@elementor/editor-elements';
|
|
10
|
+
import { type CreateOptions } from '@elementor/editor-props';
|
|
11
|
+
import { Stack, TextField } from '@elementor/ui';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
|
|
14
|
+
import { useElement } from '../../../contexts/element-context';
|
|
15
|
+
import { getElementByType } from '../get-element-by-type';
|
|
16
|
+
import { MENU_ENTRY_ELEMENT_TYPE, MENU_ITEMS_ELEMENT_TYPE, type MenuItem, useActions } from './use-actions';
|
|
17
|
+
|
|
18
|
+
export const MenuItemsControl = ( { label }: { label: string } ) => {
|
|
19
|
+
const { element } = useElement();
|
|
20
|
+
const { addItem, duplicateItem, moveItem, removeItem } = useActions();
|
|
21
|
+
|
|
22
|
+
const { [ MENU_ENTRY_ELEMENT_TYPE ]: entries } = useElementChildren( element.id, {
|
|
23
|
+
[ MENU_ITEMS_ELEMENT_TYPE ]: MENU_ENTRY_ELEMENT_TYPE,
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
const menuItems = getElementByType( element.id, MENU_ITEMS_ELEMENT_TYPE ) as V1Element | null;
|
|
27
|
+
|
|
28
|
+
const repeaterValues: RepeaterItem< MenuItem >[] = entries.map( ( entry, index ) => ( {
|
|
29
|
+
id: entry.id,
|
|
30
|
+
title: entry.editorSettings?.title,
|
|
31
|
+
index,
|
|
32
|
+
} ) );
|
|
33
|
+
|
|
34
|
+
const setValue = (
|
|
35
|
+
_newValues: RepeaterItem< MenuItem >[],
|
|
36
|
+
_options: CreateOptions,
|
|
37
|
+
meta?: SetRepeaterValuesMeta< RepeaterItem< MenuItem > >
|
|
38
|
+
) => {
|
|
39
|
+
if ( ! menuItems ) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ( meta?.action?.type === 'add' ) {
|
|
44
|
+
return addItem( {
|
|
45
|
+
menuItemsId: menuItems.id,
|
|
46
|
+
items: meta.action.payload,
|
|
47
|
+
} );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ( meta?.action?.type === 'remove' ) {
|
|
51
|
+
return removeItem( { items: meta.action.payload } );
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ( meta?.action?.type === 'duplicate' ) {
|
|
55
|
+
return duplicateItem( { items: meta.action.payload } );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if ( meta?.action?.type === 'reorder' ) {
|
|
59
|
+
const { from, to } = meta.action.payload;
|
|
60
|
+
|
|
61
|
+
return moveItem( {
|
|
62
|
+
menuItemsId: menuItems.id,
|
|
63
|
+
movedElementId: entries[ from ].id,
|
|
64
|
+
toIndex: to,
|
|
65
|
+
} );
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Repeater
|
|
71
|
+
showToggle={ false }
|
|
72
|
+
values={ repeaterValues }
|
|
73
|
+
setValues={ setValue }
|
|
74
|
+
showRemove={ repeaterValues.length > 1 }
|
|
75
|
+
label={ label }
|
|
76
|
+
adornment={ () => null }
|
|
77
|
+
itemSettings={ {
|
|
78
|
+
getId: ( { item } ) => item.id,
|
|
79
|
+
initialValues: { id: '', title: __( 'Menu item', 'elementor' ) },
|
|
80
|
+
Label: ItemLabel,
|
|
81
|
+
Content: ItemContent,
|
|
82
|
+
Icon: () => null,
|
|
83
|
+
} }
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const ItemLabel = ( { value }: { value: MenuItem } ) => (
|
|
89
|
+
<Stack sx={ { minHeight: 20 } } direction="row" alignItems="center" gap={ 1.5 }>
|
|
90
|
+
{ value.id ? (
|
|
91
|
+
<EntryLabel elementId={ value.id } fallbackTitle={ value.title } />
|
|
92
|
+
) : (
|
|
93
|
+
<span>{ value?.title }</span>
|
|
94
|
+
) }
|
|
95
|
+
</Stack>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const EntryLabel = ( { elementId, fallbackTitle }: { elementId: string; fallbackTitle?: string } ) => {
|
|
99
|
+
const editorSettings = useElementEditorSettings( elementId );
|
|
100
|
+
|
|
101
|
+
return <span>{ editorSettings?.title ?? fallbackTitle ?? '' }</span>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const ItemContent = ( { value }: { value: MenuItem } ) => {
|
|
105
|
+
if ( ! value.id ) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Stack p={ 2 } gap={ 1.5 }>
|
|
111
|
+
<ItemNameControl elementId={ value.id } />
|
|
112
|
+
</Stack>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const ItemNameControl = ( { elementId }: { elementId: string } ) => {
|
|
117
|
+
const editorSettings = useElementEditorSettings( elementId );
|
|
118
|
+
const inputId = useId();
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Stack gap={ 1 }>
|
|
122
|
+
<ControlFormLabel htmlFor={ inputId }>{ __( 'Name', 'elementor' ) }</ControlFormLabel>
|
|
123
|
+
<TextField
|
|
124
|
+
id={ inputId }
|
|
125
|
+
size="tiny"
|
|
126
|
+
value={ editorSettings?.title ?? '' }
|
|
127
|
+
onChange={ ( { target }: React.ChangeEvent< HTMLInputElement > ) => {
|
|
128
|
+
updateElementEditorSettings( { elementId, settings: { title: target.value } } );
|
|
129
|
+
} }
|
|
130
|
+
/>
|
|
131
|
+
</Stack>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
const MENU_ITEM_ELEMENT_TYPE = 'e-menu-item';
|
|
23
|
+
const PARAGRAPH_WIDGET_TYPE = 'e-paragraph';
|
|
24
|
+
|
|
25
|
+
const getEntryTitle = () => __( 'Menu item', 'elementor' );
|
|
26
|
+
|
|
27
|
+
const buildEntryModel = ( title: string ): V1ElementData => ( {
|
|
28
|
+
elType: MENU_ENTRY_ELEMENT_TYPE,
|
|
29
|
+
id: generateElementId(),
|
|
30
|
+
editor_settings: { title },
|
|
31
|
+
elements: [
|
|
32
|
+
{
|
|
33
|
+
elType: MENU_ITEM_ELEMENT_TYPE,
|
|
34
|
+
id: generateElementId(),
|
|
35
|
+
elements: [
|
|
36
|
+
{
|
|
37
|
+
elType: 'widget',
|
|
38
|
+
widgetType: PARAGRAPH_WIDGET_TYPE,
|
|
39
|
+
id: generateElementId(),
|
|
40
|
+
elements: [],
|
|
41
|
+
settings: {
|
|
42
|
+
paragraph: escapedHtmlPropTypeUtil.create( title ),
|
|
43
|
+
tag: { $$type: 'string', value: 'span' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
export const useActions = () => {
|
|
52
|
+
const addItem = ( { menuItemsId, items }: { menuItemsId: string; items: ItemsActionPayload< MenuItem > } ) => {
|
|
53
|
+
const menuItems = getContainer( menuItemsId );
|
|
54
|
+
|
|
55
|
+
if ( ! menuItems ) {
|
|
56
|
+
throw new Error( 'Menu items container not found' );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
items.forEach( () => {
|
|
60
|
+
createElements( {
|
|
61
|
+
title: __( 'Menu', 'elementor' ),
|
|
62
|
+
elements: [
|
|
63
|
+
{
|
|
64
|
+
container: menuItems,
|
|
65
|
+
model: buildEntryModel( getEntryTitle() ) as CreateElementParams[ 'model' ],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
} );
|
|
69
|
+
} );
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const removeItem = ( { items }: { items: ItemsActionPayload< MenuItem > } ) => {
|
|
73
|
+
removeElements( {
|
|
74
|
+
title: __( 'Menu', 'elementor' ),
|
|
75
|
+
elementIds: items.map( ( { item } ) => item.id ),
|
|
76
|
+
} );
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const duplicateItem = ( { items }: { items: ItemsActionPayload< MenuItem > } ) => {
|
|
80
|
+
duplicateElements( {
|
|
81
|
+
title: __( 'Duplicate Menu item', 'elementor' ),
|
|
82
|
+
elementIds: items.map( ( { item } ) => item.id ),
|
|
83
|
+
} );
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const moveItem = ( {
|
|
87
|
+
menuItemsId,
|
|
88
|
+
movedElementId,
|
|
89
|
+
toIndex,
|
|
90
|
+
}: {
|
|
91
|
+
menuItemsId: string;
|
|
92
|
+
movedElementId: string;
|
|
93
|
+
toIndex: number;
|
|
94
|
+
} ) => {
|
|
95
|
+
const menuItems = getContainer( menuItemsId );
|
|
96
|
+
const movedElement = getContainer( movedElementId );
|
|
97
|
+
|
|
98
|
+
if ( ! menuItems || ! movedElement ) {
|
|
99
|
+
throw new Error( 'Menu item or container not found' );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
moveElements( {
|
|
103
|
+
title: __( 'Reorder Menu items', 'elementor' ),
|
|
104
|
+
moves: [
|
|
105
|
+
{
|
|
106
|
+
element: movedElement,
|
|
107
|
+
targetContainer: menuItems,
|
|
108
|
+
options: { at: toIndex },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
} );
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return { addItem, removeItem, duplicateItem, moveItem };
|
|
115
|
+
};
|
|
@@ -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;
|