@elementor/editor-components 3.35.0-332 → 3.35.0-334

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-components",
3
3
  "description": "Elementor editor components",
4
- "version": "3.35.0-332",
4
+ "version": "3.35.0-334",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,28 +40,28 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor": "3.35.0-332",
44
- "@elementor/editor-canvas": "3.35.0-332",
45
- "@elementor/editor-controls": "3.35.0-332",
46
- "@elementor/editor-documents": "3.35.0-332",
47
- "@elementor/editor-editing-panel": "3.35.0-332",
48
- "@elementor/editor-elements": "3.35.0-332",
49
- "@elementor/editor-elements-panel": "3.35.0-332",
50
- "@elementor/editor-mcp": "3.35.0-332",
51
- "@elementor/editor-props": "3.35.0-332",
52
- "@elementor/editor-styles-repository": "3.35.0-332",
53
- "@elementor/editor-ui": "3.35.0-332",
54
- "@elementor/editor-v1-adapters": "3.35.0-332",
55
- "@elementor/http-client": "3.35.0-332",
43
+ "@elementor/editor": "3.35.0-334",
44
+ "@elementor/editor-canvas": "3.35.0-334",
45
+ "@elementor/editor-controls": "3.35.0-334",
46
+ "@elementor/editor-documents": "3.35.0-334",
47
+ "@elementor/editor-editing-panel": "3.35.0-334",
48
+ "@elementor/editor-elements": "3.35.0-334",
49
+ "@elementor/editor-elements-panel": "3.35.0-334",
50
+ "@elementor/editor-mcp": "3.35.0-334",
51
+ "@elementor/editor-props": "3.35.0-334",
52
+ "@elementor/editor-styles-repository": "3.35.0-334",
53
+ "@elementor/editor-ui": "3.35.0-334",
54
+ "@elementor/editor-v1-adapters": "3.35.0-334",
55
+ "@elementor/http-client": "3.35.0-334",
56
56
  "@elementor/icons": "^1.62.0",
57
- "@elementor/mixpanel": "3.35.0-332",
58
- "@elementor/query": "3.35.0-332",
59
- "@elementor/schema": "3.35.0-332",
60
- "@elementor/store": "3.35.0-332",
57
+ "@elementor/mixpanel": "3.35.0-334",
58
+ "@elementor/query": "3.35.0-334",
59
+ "@elementor/schema": "3.35.0-334",
60
+ "@elementor/store": "3.35.0-334",
61
61
  "@elementor/ui": "1.36.17",
62
- "@elementor/utils": "3.35.0-332",
62
+ "@elementor/utils": "3.35.0-334",
63
63
  "@wordpress/i18n": "^5.13.0",
64
- "@elementor/editor-notifications": "3.35.0-332"
64
+ "@elementor/editor-notifications": "3.35.0-334"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "react": "^18.3.1",
@@ -9,6 +9,7 @@ import {
9
9
  componentOverridablePropTypeUtil,
10
10
  type ComponentOverridablePropValue,
11
11
  } from '../../prop-types/component-overridable-prop-type';
12
+ import { OverridablePropProvider } from '../../provider/overridable-prop-context';
12
13
  import { updateOverridablePropOriginValue } from '../../store/actions/update-overridable-prop-origin-value';
13
14
  import { selectCurrentComponentId } from '../../store/store';
14
15
 
@@ -50,18 +51,20 @@ export function OverridablePropControl< T extends object >( {
50
51
  : undefined;
51
52
 
52
53
  return (
53
- <PropProvider
54
- { ...propContext }
55
- propType={ propType }
56
- setValue={ setOverridableValue }
57
- value={ { [ bind ]: value.origin_value } }
58
- placeholder={ objectPlaceholder }
59
- >
60
- <PropKeyProvider bind={ bind }>
61
- <ControlReplacementsProvider replacements={ [] }>
62
- <OriginalControl { ...( props as T ) } />
63
- </ControlReplacementsProvider>
64
- </PropKeyProvider>
65
- </PropProvider>
54
+ <OverridablePropProvider value={ value }>
55
+ <PropProvider
56
+ { ...propContext }
57
+ propType={ propType }
58
+ setValue={ setOverridableValue }
59
+ value={ { [ bind ]: value.origin_value } }
60
+ placeholder={ objectPlaceholder }
61
+ >
62
+ <PropKeyProvider bind={ bind }>
63
+ <ControlReplacementsProvider replacements={ [] }>
64
+ <OriginalControl { ...( props as T ) } />
65
+ </ControlReplacementsProvider>
66
+ </PropKeyProvider>
67
+ </PropProvider>
68
+ </OverridablePropProvider>
66
69
  );
67
70
  }
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import { useBoundProp } from '@elementor/editor-controls';
3
- import { getV1CurrentDocument } from '@elementor/editor-documents';
4
3
  import { useElement } from '@elementor/editor-editing-panel';
5
4
  import { getWidgetsCache } from '@elementor/editor-elements';
6
5
  import { type TransformablePropValue } from '@elementor/editor-props';
@@ -9,10 +8,10 @@ import { bindPopover, bindTrigger, Popover, Tooltip, usePopupState } from '@elem
9
8
  import { __ } from '@wordpress/i18n';
10
9
 
11
10
  import { componentOverridablePropTypeUtil } from '../../prop-types/component-overridable-prop-type';
11
+ import { useOverridablePropValue } from '../../provider/overridable-prop-context';
12
12
  import { setOverridableProp } from '../../store/actions/set-overridable-prop';
13
- import { selectOverridableProps } from '../../store/store';
13
+ import { selectCurrentComponentId, selectOverridableProps } from '../../store/store';
14
14
  import { type OverridableProps } from '../../types';
15
- import { COMPONENT_DOCUMENT_TYPE } from '../consts';
16
15
  import { Indicator } from './indicator';
17
16
  import { OverridablePropForm } from './overridable-prop-form';
18
17
  import { getOverridableProp } from './utils/get-overridable-prop';
@@ -21,19 +20,15 @@ const FORBIDDEN_KEYS = [ '_cssid', 'attributes' ];
21
20
 
22
21
  export function OverridablePropIndicator() {
23
22
  const { bind } = useBoundProp();
24
- const currentDocument = getV1CurrentDocument();
23
+ const componentId = selectCurrentComponentId( getState() );
25
24
 
26
- if ( currentDocument.config.type !== COMPONENT_DOCUMENT_TYPE || ! currentDocument.id ) {
25
+ if ( ! isPropAllowed( bind ) || ! componentId ) {
27
26
  return null;
28
27
  }
29
28
 
30
- if ( ! isPropAllowed( bind ) ) {
31
- return null;
32
- }
33
-
34
- const overridableProps = selectOverridableProps( getState(), currentDocument.id );
29
+ const overridableProps = selectOverridableProps( getState(), componentId );
35
30
 
36
- return <Content componentId={ currentDocument.id } overridableProps={ overridableProps } />;
31
+ return <Content componentId={ componentId } overridableProps={ overridableProps } />;
37
32
  }
38
33
 
39
34
  type Props = {
@@ -46,7 +41,17 @@ export function Content( { componentId, overridableProps }: Props ) {
46
41
  elementType,
47
42
  } = useElement();
48
43
  const { value, bind, propType } = useBoundProp();
49
- const { value: overridableValue, setValue: setOverridableValue } = useBoundProp( componentOverridablePropTypeUtil );
44
+
45
+ const contextOverridableValue = useOverridablePropValue();
46
+ const { value: boundPropOverridableValue, setValue: setOverridableValue } = useBoundProp(
47
+ componentOverridablePropTypeUtil
48
+ );
49
+
50
+ /**
51
+ * This is intended to handle custom layout controls, such as <LinkControl />, which has <ControlLabel /> nested within it
52
+ * i.e. its bound prop value would be the one manipulated by the new <PropProvider /> thus won't be considered overridable
53
+ */
54
+ const overridableValue = boundPropOverridableValue ?? contextOverridableValue;
50
55
 
51
56
  const popupState = usePopupState( {
52
57
  variant: 'popover',
@@ -17,8 +17,48 @@ import { trackComponentEvent } from './utils/tracking';
17
17
 
18
18
  type ContextMenuEventData = { location: string; secondaryLocation: string; trigger: string };
19
19
 
20
+ export type ContextMenuAction = {
21
+ name: string;
22
+ icon: string;
23
+ title: string | ( () => string );
24
+ isEnabled: () => boolean;
25
+ callback: ( _: unknown, eventData: ContextMenuEventData ) => void;
26
+ };
27
+
28
+ type ContextMenuGroupConfig = {
29
+ disable: Record< string, string[] >;
30
+ add: Record< string, { index: number; action: ContextMenuAction } >;
31
+ };
32
+
33
+ type ContextMenuGroup = {
34
+ name: string;
35
+ actions: ContextMenuAction[];
36
+ };
37
+
20
38
  export const TYPE = 'e-component';
21
39
 
40
+ const updateGroups = ( groups: ContextMenuGroup[], config: ContextMenuGroupConfig ): ContextMenuGroup[] => {
41
+ const disableMap = new Map( Object.entries( config.disable ?? {} ) );
42
+ const addMap = new Map( Object.entries( config.add ?? {} ) );
43
+
44
+ return groups.map( ( group ) => {
45
+ const disabledActions = disableMap.get( group.name ) ?? [];
46
+ const addConfig = addMap.get( group.name );
47
+
48
+ // Update disabled actions
49
+ const updatedActions = group.actions.map( ( action ) =>
50
+ disabledActions.includes( action.name ) ? { ...action, isEnabled: () => false } : action
51
+ );
52
+
53
+ // Insert additional action if needed
54
+ if ( addConfig ) {
55
+ updatedActions.splice( addConfig.index, 0, addConfig.action );
56
+ }
57
+
58
+ return { ...group, actions: updatedActions };
59
+ } );
60
+ };
61
+
22
62
  export function createComponentType(
23
63
  options: CreateTemplatedElementTypeOptions & { showLockedByModal?: ( lockedBy: string ) => void }
24
64
  ): typeof ElementType {
@@ -30,13 +70,15 @@ export function createComponentType(
30
70
  }
31
71
 
32
72
  getView() {
33
- return createComponentView( options );
73
+ return createComponentView( { ...options } );
34
74
  }
35
75
  };
36
76
  }
37
77
 
38
78
  function createComponentView(
39
- options: CreateTemplatedElementTypeOptions & { showLockedByModal?: ( lockedBy: string ) => void }
79
+ options: CreateTemplatedElementTypeOptions & {
80
+ showLockedByModal?: ( lockedBy: string ) => void;
81
+ }
40
82
  ): typeof ElementView {
41
83
  return class extends createTemplatedElementView( options ) {
42
84
  legacyWindow = window as unknown as LegacyWindow & ExtendedWindow;
@@ -94,22 +136,38 @@ function createComponentView(
94
136
  return filteredGroups;
95
137
  }
96
138
 
97
- const newGroup = [
98
- {
99
- name: 'edit component',
100
- actions: [
101
- {
102
- name: 'edit component',
103
- icon: 'eicon-edit',
104
- title: () => __( 'Edit Component', 'elementor' ),
105
- isEnabled: () => true,
106
- callback: ( _: unknown, eventData: ContextMenuEventData ) =>
107
- this.editComponent( eventData ),
108
- },
109
- ],
139
+ const newGroups = updateGroups(
140
+ filteredGroups as ContextMenuGroup[],
141
+ this._getContextMenuConfig() as unknown as ContextMenuGroupConfig
142
+ );
143
+ return newGroups;
144
+ }
145
+
146
+ _getContextMenuConfig() {
147
+ const legacyWindow = this.legacyWindow || ( window as unknown as LegacyWindow & ExtendedWindow );
148
+ const elementorWithConfig = legacyWindow.elementor as typeof legacyWindow.elementor & {
149
+ config?: { user?: { is_administrator?: boolean } };
150
+ };
151
+ const isAdministrator = elementorWithConfig.config?.user?.is_administrator ?? false;
152
+
153
+ const addedGroup = {
154
+ general: {
155
+ index: 1,
156
+ action: {
157
+ name: 'edit component',
158
+ icon: 'eicon-edit',
159
+ title: () => __( 'Edit Component', 'elementor' ),
160
+ isEnabled: () => true,
161
+ callback: ( _: unknown, eventData: ContextMenuEventData ) => this.editComponent( eventData ),
162
+ },
110
163
  },
111
- ];
112
- return [ ...filteredGroups, ...newGroup ];
164
+ };
165
+
166
+ const disabledGroup = {
167
+ clipboard: [ 'pasteStyle', 'resetStyle' ],
168
+ };
169
+
170
+ return { add: isAdministrator ? addedGroup : {}, disable: disabledGroup };
113
171
  }
114
172
 
115
173
  async switchDocument() {
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { createContext, type PropsWithChildren, useContext } from 'react';
3
+
4
+ import { type ComponentOverridablePropValue } from '../prop-types/component-overridable-prop-type';
5
+
6
+ type OverridablePropData = {
7
+ value: ComponentOverridablePropValue;
8
+ };
9
+
10
+ const OverridablePropContext = createContext< OverridablePropData | null >( null );
11
+
12
+ export function OverridablePropProvider( { children, ...props }: PropsWithChildren< OverridablePropData > ) {
13
+ return <OverridablePropContext.Provider value={ props }>{ children }</OverridablePropContext.Provider>;
14
+ }
15
+
16
+ export const useOverridablePropValue = () => useContext( OverridablePropContext )?.value;