@elementor/editor-components 4.0.0-650 → 4.0.0-660

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": "4.0.0-650",
4
+ "version": "4.0.0-660",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,31 +40,31 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor": "4.0.0-650",
44
- "@elementor/editor-canvas": "4.0.0-650",
45
- "@elementor/editor-controls": "4.0.0-650",
46
- "@elementor/editor-documents": "4.0.0-650",
47
- "@elementor/editor-editing-panel": "4.0.0-650",
48
- "@elementor/editor-elements": "4.0.0-650",
49
- "@elementor/editor-elements-panel": "4.0.0-650",
50
- "@elementor/editor-mcp": "4.0.0-650",
51
- "@elementor/editor-templates": "4.0.0-650",
52
- "@elementor/editor-panels": "4.0.0-650",
53
- "@elementor/editor-props": "4.0.0-650",
54
- "@elementor/editor-styles-repository": "4.0.0-650",
55
- "@elementor/editor-ui": "4.0.0-650",
56
- "@elementor/editor-v1-adapters": "4.0.0-650",
57
- "@elementor/http-client": "4.0.0-650",
43
+ "@elementor/editor": "4.0.0-660",
44
+ "@elementor/editor-canvas": "4.0.0-660",
45
+ "@elementor/editor-controls": "4.0.0-660",
46
+ "@elementor/editor-documents": "4.0.0-660",
47
+ "@elementor/editor-editing-panel": "4.0.0-660",
48
+ "@elementor/editor-elements": "4.0.0-660",
49
+ "@elementor/editor-elements-panel": "4.0.0-660",
50
+ "@elementor/editor-mcp": "4.0.0-660",
51
+ "@elementor/editor-templates": "4.0.0-660",
52
+ "@elementor/editor-panels": "4.0.0-660",
53
+ "@elementor/editor-props": "4.0.0-660",
54
+ "@elementor/editor-styles-repository": "4.0.0-660",
55
+ "@elementor/editor-ui": "4.0.0-660",
56
+ "@elementor/editor-v1-adapters": "4.0.0-660",
57
+ "@elementor/http-client": "4.0.0-660",
58
58
  "@elementor/icons": "^1.68.0",
59
- "@elementor/events": "4.0.0-650",
60
- "@elementor/query": "4.0.0-650",
61
- "@elementor/schema": "4.0.0-650",
62
- "@elementor/store": "4.0.0-650",
59
+ "@elementor/events": "4.0.0-660",
60
+ "@elementor/query": "4.0.0-660",
61
+ "@elementor/schema": "4.0.0-660",
62
+ "@elementor/store": "4.0.0-660",
63
63
  "@elementor/ui": "1.36.17",
64
- "@elementor/utils": "4.0.0-650",
64
+ "@elementor/utils": "4.0.0-660",
65
65
  "@wordpress/i18n": "^5.13.0",
66
- "@elementor/editor-notifications": "4.0.0-650",
67
- "@elementor/editor-current-user": "4.0.0-650"
66
+ "@elementor/editor-notifications": "4.0.0-660",
67
+ "@elementor/editor-current-user": "4.0.0-660"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "react": "^18.3.1",
@@ -0,0 +1,121 @@
1
+ import { getElementType, getSelectedElements, getWidgetsCache } from '@elementor/editor-elements';
2
+ import { isProActive } from '@elementor/utils';
3
+
4
+ type LegacyWindow = {
5
+ $e: {
6
+ shortcuts: {
7
+ register: ( keys: string, config: ShortcutConfig ) => void;
8
+ };
9
+ };
10
+ elementor: {
11
+ getContainer: ( id: string ) => Container;
12
+ $preview: Array< { getBoundingClientRect: () => DOMRect } >;
13
+ };
14
+ };
15
+
16
+ type Container = {
17
+ isLocked: () => boolean;
18
+ model: {
19
+ id: string;
20
+ toJSON: ( options?: { remove?: string[] } ) => Record< string, unknown >;
21
+ };
22
+ view: {
23
+ el: HTMLElement;
24
+ };
25
+ };
26
+
27
+ type ShortcutConfig = {
28
+ callback: () => void;
29
+ dependency?: () => boolean;
30
+ exclude?: string[];
31
+ };
32
+
33
+ export const CREATE_COMPONENT_SHORTCUT_KEYS = 'ctrl+shift+k';
34
+ const OPEN_SAVE_AS_COMPONENT_FORM_EVENT = 'elementor/editor/open-save-as-component-form';
35
+
36
+ type CreateComponentAllowedResult = { allowed: true; container: Container } | { allowed: false; container?: undefined };
37
+
38
+ export function isCreateComponentAllowed(): CreateComponentAllowedResult {
39
+ const selectedElements = getSelectedElements();
40
+
41
+ if ( selectedElements.length !== 1 ) {
42
+ return { allowed: false };
43
+ }
44
+
45
+ const element = selectedElements[ 0 ];
46
+ const elementType = getElementType( element.type );
47
+
48
+ if ( ! elementType ) {
49
+ return { allowed: false };
50
+ }
51
+
52
+ if ( ! isProActive() ) {
53
+ return { allowed: false };
54
+ }
55
+
56
+ const widgetsCache = getWidgetsCache();
57
+ const elementConfig = widgetsCache?.[ element.type ];
58
+
59
+ if (
60
+ ! elementConfig?.atomic_props_schema ||
61
+ ! elementConfig?.show_in_panel ||
62
+ elementConfig?.elType === 'widget'
63
+ ) {
64
+ return { allowed: false };
65
+ }
66
+
67
+ const legacyWindow = window as unknown as LegacyWindow;
68
+ const container = legacyWindow.elementor.getContainer( element.id );
69
+
70
+ if ( ! container || container.isLocked() ) {
71
+ return { allowed: false };
72
+ }
73
+
74
+ return { allowed: true, container };
75
+ }
76
+
77
+ export function triggerCreateComponentForm( container: Container ): void {
78
+ const legacyWindow = window as unknown as LegacyWindow;
79
+ const elementRect = container.view.el.getBoundingClientRect();
80
+ const iframeRect = legacyWindow.elementor.$preview[ 0 ].getBoundingClientRect();
81
+
82
+ const anchorPosition = {
83
+ left: iframeRect.left + elementRect.left + elementRect.width / 2,
84
+ top: iframeRect.top + elementRect.top,
85
+ };
86
+
87
+ window.dispatchEvent(
88
+ new CustomEvent( OPEN_SAVE_AS_COMPONENT_FORM_EVENT, {
89
+ detail: {
90
+ element: container.model.toJSON( { remove: [ 'default' ] } ),
91
+ anchorPosition,
92
+ options: {
93
+ trigger: 'keyboard',
94
+ location: 'canvas',
95
+ secondaryLocation: 'canvasElement',
96
+ },
97
+ },
98
+ } )
99
+ );
100
+ }
101
+
102
+ export function initCreateComponentShortcut(): void {
103
+ const legacyWindow = window as unknown as LegacyWindow;
104
+
105
+ legacyWindow.$e.shortcuts.register( CREATE_COMPONENT_SHORTCUT_KEYS, {
106
+ callback: () => {
107
+ const result = isCreateComponentAllowed();
108
+
109
+ if ( ! result.allowed ) {
110
+ return;
111
+ }
112
+
113
+ triggerCreateComponentForm( result.container );
114
+ },
115
+ dependency: () => {
116
+ const result = isCreateComponentAllowed();
117
+ return result.allowed;
118
+ },
119
+ exclude: [ 'input' ],
120
+ } );
121
+ }
@@ -47,7 +47,7 @@ export async function createUnpublishedComponent( {
47
47
 
48
48
  componentsActions.addCreatedThisSession( generatedUid );
49
49
 
50
- const componentInstance = await replaceElementWithComponent( element, componentBase );
50
+ const componentInstance = replaceElementWithComponent( element, componentBase );
51
51
 
52
52
  trackComponentEvent( {
53
53
  action: 'created',
@@ -2,9 +2,9 @@ import { replaceElement, type V1ElementData } from '@elementor/editor-elements';
2
2
 
3
3
  import { type ComponentInstanceParams, createComponentModel } from './create-component-model';
4
4
 
5
- export const replaceElementWithComponent = async ( element: V1ElementData, component: ComponentInstanceParams ) => {
6
- return await replaceElement( {
7
- currentElement: element,
5
+ export const replaceElementWithComponent = ( element: V1ElementData, component: ComponentInstanceParams ) => {
6
+ return replaceElement( {
7
+ currentElementId: element.id,
8
8
  newElement: createComponentModel( component ),
9
9
  withHistory: false,
10
10
  } );
package/src/init.ts CHANGED
@@ -23,6 +23,7 @@ import { InstanceEditingPanel } from './components/instance-editing-panel/instan
23
23
  import { LoadTemplateComponents } from './components/load-template-components';
24
24
  import { COMPONENT_WIDGET_TYPE, createComponentType } from './create-component-type';
25
25
  import { initExtended } from './extended/init';
26
+ import { initCreateComponentShortcut } from './extended/shortcuts/create-component-shortcut';
26
27
  import { PopulateStore } from './populate-store';
27
28
  import { initCircularNestingPrevention } from './prevent-circular-nesting';
28
29
  import { loadComponentsAssets } from './store/actions/load-components-assets';
@@ -90,4 +91,8 @@ export function init() {
90
91
  if ( !! window.elementorPro && ! isProAtLeast( PRO_EXTENDED_MIGRATION_VERSION ) ) {
91
92
  initExtended();
92
93
  }
94
+
95
+ if ( !! window.elementorPro ) {
96
+ initCreateComponentShortcut();
97
+ }
93
98
  }