@elementor/editor-editing-panel 4.5.0-1181 → 4.5.0-1182

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-editing-panel",
3
- "version": "4.5.0-1181",
3
+ "version": "4.5.0-1182",
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-1181",
43
- "@elementor/editor-canvas": "4.5.0-1181",
44
- "@elementor/editor-controls": "4.5.0-1181",
45
- "@elementor/editor-current-user": "4.5.0-1181",
46
- "@elementor/editor-documents": "4.5.0-1181",
47
- "@elementor/editor-elements": "4.5.0-1181",
48
- "@elementor/editor-interactions": "4.5.0-1181",
49
- "@elementor/editor-notifications": "4.5.0-1181",
50
- "@elementor/editor-panels": "4.5.0-1181",
51
- "@elementor/editor-props": "4.5.0-1181",
52
- "@elementor/editor-responsive": "4.5.0-1181",
53
- "@elementor/editor-styles": "4.5.0-1181",
54
- "@elementor/editor-styles-repository": "4.5.0-1181",
55
- "@elementor/editor-ui": "4.5.0-1181",
56
- "@elementor/editor-v1-adapters": "4.5.0-1181",
57
- "@elementor/http-client": "4.5.0-1181",
42
+ "@elementor/editor": "4.5.0-1182",
43
+ "@elementor/editor-canvas": "4.5.0-1182",
44
+ "@elementor/editor-controls": "4.5.0-1182",
45
+ "@elementor/editor-current-user": "4.5.0-1182",
46
+ "@elementor/editor-documents": "4.5.0-1182",
47
+ "@elementor/editor-elements": "4.5.0-1182",
48
+ "@elementor/editor-interactions": "4.5.0-1182",
49
+ "@elementor/editor-notifications": "4.5.0-1182",
50
+ "@elementor/editor-panels": "4.5.0-1182",
51
+ "@elementor/editor-props": "4.5.0-1182",
52
+ "@elementor/editor-responsive": "4.5.0-1182",
53
+ "@elementor/editor-styles": "4.5.0-1182",
54
+ "@elementor/editor-styles-repository": "4.5.0-1182",
55
+ "@elementor/editor-ui": "4.5.0-1182",
56
+ "@elementor/editor-v1-adapters": "4.5.0-1182",
57
+ "@elementor/http-client": "4.5.0-1182",
58
58
  "@elementor/icons": "~1.78.1",
59
- "@elementor/editor-variables": "4.5.0-1181",
60
- "@elementor/locations": "4.5.0-1181",
61
- "@elementor/menus": "4.5.0-1181",
62
- "@elementor/query": "4.5.0-1181",
63
- "@elementor/schema": "4.5.0-1181",
64
- "@elementor/session": "4.5.0-1181",
59
+ "@elementor/editor-variables": "4.5.0-1182",
60
+ "@elementor/locations": "4.5.0-1182",
61
+ "@elementor/menus": "4.5.0-1182",
62
+ "@elementor/query": "4.5.0-1182",
63
+ "@elementor/schema": "4.5.0-1182",
64
+ "@elementor/session": "4.5.0-1182",
65
65
  "@elementor/ui": "1.41.4",
66
- "@elementor/utils": "4.5.0-1181",
67
- "@elementor/wp-media": "4.5.0-1181",
66
+ "@elementor/utils": "4.5.0-1182",
67
+ "@elementor/wp-media": "4.5.0-1182",
68
68
  "@wordpress/i18n": "^5.13.0"
69
69
  },
70
70
  "peerDependencies": {
@@ -2,18 +2,32 @@ import * as React from 'react';
2
2
  import { useId } from 'react';
3
3
  import { ControlFormLabel, Repeater, type RepeaterItem, type SetRepeaterValuesMeta } from '@elementor/editor-controls';
4
4
  import {
5
+ type Control,
6
+ type ControlItem,
7
+ getElementType,
5
8
  updateElementEditorSettings,
6
9
  useElementChildren,
7
10
  useElementEditorSettings,
8
11
  type V1Element,
9
12
  } from '@elementor/editor-elements';
10
13
  import { type CreateOptions } from '@elementor/editor-props';
14
+ import { SessionStorageProvider } from '@elementor/session';
11
15
  import { Stack, TextField } from '@elementor/ui';
12
16
  import { __ } from '@wordpress/i18n';
13
17
 
14
- import { useElement } from '../../../contexts/element-context';
18
+ import { SettingsControl } from '../../../components/settings-control';
19
+ import { ElementProvider, useElement } from '../../../contexts/element-context';
15
20
  import { getElementByType } from '../get-element-by-type';
16
- import { MENU_ENTRY_ELEMENT_TYPE, MENU_ITEMS_ELEMENT_TYPE, type MenuItem, useActions } from './use-actions';
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';
17
31
 
18
32
  export const MenuItemsControl = ( { label }: { label: string } ) => {
19
33
  const { element } = useElement();
@@ -48,7 +62,7 @@ export const MenuItemsControl = ( { label }: { label: string } ) => {
48
62
  }
49
63
 
50
64
  if ( meta?.action?.type === 'remove' ) {
51
- return removeItem( { items: meta.action.payload } );
65
+ return removeItem( { menuItemsId: menuItems.id, items: meta.action.payload } );
52
66
  }
53
67
 
54
68
  if ( meta?.action?.type === 'duplicate' ) {
@@ -109,6 +123,7 @@ const ItemContent = ( { value }: { value: MenuItem } ) => {
109
123
  return (
110
124
  <Stack p={ 2 } gap={ 1.5 }>
111
125
  <ItemNameControl elementId={ value.id } />
126
+ <ItemLinkControl entryId={ value.id } />
112
127
  </Stack>
113
128
  );
114
129
  };
@@ -119,7 +134,7 @@ const ItemNameControl = ( { elementId }: { elementId: string } ) => {
119
134
 
120
135
  return (
121
136
  <Stack gap={ 1 }>
122
- <ControlFormLabel htmlFor={ inputId }>{ __( 'Name', 'elementor' ) }</ControlFormLabel>
137
+ <ControlFormLabel htmlFor={ inputId }>{ __( 'Item name', 'elementor' ) }</ControlFormLabel>
123
138
  <TextField
124
139
  id={ inputId }
125
140
  size="tiny"
@@ -131,3 +146,43 @@ const ItemNameControl = ( { elementId }: { elementId: string } ) => {
131
146
  </Stack>
132
147
  );
133
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
+ };
@@ -19,7 +19,8 @@ export type MenuItem = {
19
19
 
20
20
  export const MENU_ITEMS_ELEMENT_TYPE = 'e-menu-items';
21
21
  export const MENU_ENTRY_ELEMENT_TYPE = 'e-menu-entry';
22
- const MENU_ITEM_ELEMENT_TYPE = 'e-menu-item';
22
+ export const MENU_ITEM_ELEMENT_TYPE = 'e-menu-item';
23
+ const MIN_ENTRIES = 1;
23
24
  const PARAGRAPH_WIDGET_TYPE = 'e-paragraph';
24
25
 
25
26
  const getEntryTitle = () => __( 'Menu item', 'elementor' );
@@ -69,10 +70,20 @@ export const useActions = () => {
69
70
  } );
70
71
  };
71
72
 
72
- const removeItem = ( { items }: { items: ItemsActionPayload< MenuItem > } ) => {
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
+
73
84
  removeElements( {
74
85
  title: __( 'Menu', 'elementor' ),
75
- elementIds: items.map( ( { item } ) => item.id ),
86
+ elementIds: items.slice( 0, removableCount ).map( ( { item } ) => item.id ),
76
87
  } );
77
88
  };
78
89
 
@@ -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
+ };