@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/dist/index.js +84 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -23
- package/src/extended/shortcuts/create-component-shortcut.ts +121 -0
- package/src/extended/store/actions/create-unpublished-component.ts +1 -1
- package/src/extended/utils/replace-element-with-component.ts +3 -3
- package/src/init.ts +5 -0
package/dist/index.mjs
CHANGED
|
@@ -3882,9 +3882,9 @@ import { __ as __24 } from "@wordpress/i18n";
|
|
|
3882
3882
|
|
|
3883
3883
|
// src/extended/utils/replace-element-with-component.ts
|
|
3884
3884
|
import { replaceElement } from "@elementor/editor-elements";
|
|
3885
|
-
var replaceElementWithComponent =
|
|
3886
|
-
return
|
|
3887
|
-
|
|
3885
|
+
var replaceElementWithComponent = (element, component) => {
|
|
3886
|
+
return replaceElement({
|
|
3887
|
+
currentElementId: element.id,
|
|
3888
3888
|
newElement: createComponentModel2(component),
|
|
3889
3889
|
withHistory: false
|
|
3890
3890
|
});
|
|
@@ -3915,7 +3915,7 @@ async function createUnpublishedComponent({
|
|
|
3915
3915
|
overridableProps
|
|
3916
3916
|
});
|
|
3917
3917
|
componentsActions.addCreatedThisSession(generatedUid);
|
|
3918
|
-
const componentInstance =
|
|
3918
|
+
const componentInstance = replaceElementWithComponent(element, componentBase);
|
|
3919
3919
|
trackComponentEvent({
|
|
3920
3920
|
action: "created",
|
|
3921
3921
|
source,
|
|
@@ -4154,7 +4154,7 @@ function CreateComponentForm() {
|
|
|
4154
4154
|
const { components } = useComponents();
|
|
4155
4155
|
const eventData = useRef5(null);
|
|
4156
4156
|
useEffect3(() => {
|
|
4157
|
-
const
|
|
4157
|
+
const OPEN_SAVE_AS_COMPONENT_FORM_EVENT2 = "elementor/editor/open-save-as-component-form";
|
|
4158
4158
|
const openPopup = (event) => {
|
|
4159
4159
|
const { shouldOpen, notification } = shouldOpenForm(event.detail.element, components?.length ?? 0);
|
|
4160
4160
|
if (!shouldOpen) {
|
|
@@ -4170,9 +4170,9 @@ function CreateComponentForm() {
|
|
|
4170
4170
|
...eventData.current
|
|
4171
4171
|
});
|
|
4172
4172
|
};
|
|
4173
|
-
window.addEventListener(
|
|
4173
|
+
window.addEventListener(OPEN_SAVE_AS_COMPONENT_FORM_EVENT2, openPopup);
|
|
4174
4174
|
return () => {
|
|
4175
|
-
window.removeEventListener(
|
|
4175
|
+
window.removeEventListener(OPEN_SAVE_AS_COMPONENT_FORM_EVENT2, openPopup);
|
|
4176
4176
|
};
|
|
4177
4177
|
}, [components?.length]);
|
|
4178
4178
|
const handleSave = async (values) => {
|
|
@@ -5768,6 +5768,76 @@ function initExtended() {
|
|
|
5768
5768
|
});
|
|
5769
5769
|
}
|
|
5770
5770
|
|
|
5771
|
+
// src/extended/shortcuts/create-component-shortcut.ts
|
|
5772
|
+
import { getElementType as getElementType5, getSelectedElements as getSelectedElements2, getWidgetsCache as getWidgetsCache5 } from "@elementor/editor-elements";
|
|
5773
|
+
import { isProActive } from "@elementor/utils";
|
|
5774
|
+
var CREATE_COMPONENT_SHORTCUT_KEYS = "ctrl+shift+k";
|
|
5775
|
+
var OPEN_SAVE_AS_COMPONENT_FORM_EVENT = "elementor/editor/open-save-as-component-form";
|
|
5776
|
+
function isCreateComponentAllowed() {
|
|
5777
|
+
const selectedElements = getSelectedElements2();
|
|
5778
|
+
if (selectedElements.length !== 1) {
|
|
5779
|
+
return { allowed: false };
|
|
5780
|
+
}
|
|
5781
|
+
const element = selectedElements[0];
|
|
5782
|
+
const elementType = getElementType5(element.type);
|
|
5783
|
+
if (!elementType) {
|
|
5784
|
+
return { allowed: false };
|
|
5785
|
+
}
|
|
5786
|
+
if (!isProActive()) {
|
|
5787
|
+
return { allowed: false };
|
|
5788
|
+
}
|
|
5789
|
+
const widgetsCache = getWidgetsCache5();
|
|
5790
|
+
const elementConfig = widgetsCache?.[element.type];
|
|
5791
|
+
if (!elementConfig?.atomic_props_schema || !elementConfig?.show_in_panel || elementConfig?.elType === "widget") {
|
|
5792
|
+
return { allowed: false };
|
|
5793
|
+
}
|
|
5794
|
+
const legacyWindow = window;
|
|
5795
|
+
const container = legacyWindow.elementor.getContainer(element.id);
|
|
5796
|
+
if (!container || container.isLocked()) {
|
|
5797
|
+
return { allowed: false };
|
|
5798
|
+
}
|
|
5799
|
+
return { allowed: true, container };
|
|
5800
|
+
}
|
|
5801
|
+
function triggerCreateComponentForm(container) {
|
|
5802
|
+
const legacyWindow = window;
|
|
5803
|
+
const elementRect = container.view.el.getBoundingClientRect();
|
|
5804
|
+
const iframeRect = legacyWindow.elementor.$preview[0].getBoundingClientRect();
|
|
5805
|
+
const anchorPosition = {
|
|
5806
|
+
left: iframeRect.left + elementRect.left + elementRect.width / 2,
|
|
5807
|
+
top: iframeRect.top + elementRect.top
|
|
5808
|
+
};
|
|
5809
|
+
window.dispatchEvent(
|
|
5810
|
+
new CustomEvent(OPEN_SAVE_AS_COMPONENT_FORM_EVENT, {
|
|
5811
|
+
detail: {
|
|
5812
|
+
element: container.model.toJSON({ remove: ["default"] }),
|
|
5813
|
+
anchorPosition,
|
|
5814
|
+
options: {
|
|
5815
|
+
trigger: "keyboard",
|
|
5816
|
+
location: "canvas",
|
|
5817
|
+
secondaryLocation: "canvasElement"
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
})
|
|
5821
|
+
);
|
|
5822
|
+
}
|
|
5823
|
+
function initCreateComponentShortcut() {
|
|
5824
|
+
const legacyWindow = window;
|
|
5825
|
+
legacyWindow.$e.shortcuts.register(CREATE_COMPONENT_SHORTCUT_KEYS, {
|
|
5826
|
+
callback: () => {
|
|
5827
|
+
const result = isCreateComponentAllowed();
|
|
5828
|
+
if (!result.allowed) {
|
|
5829
|
+
return;
|
|
5830
|
+
}
|
|
5831
|
+
triggerCreateComponentForm(result.container);
|
|
5832
|
+
},
|
|
5833
|
+
dependency: () => {
|
|
5834
|
+
const result = isCreateComponentAllowed();
|
|
5835
|
+
return result.allowed;
|
|
5836
|
+
},
|
|
5837
|
+
exclude: ["input"]
|
|
5838
|
+
});
|
|
5839
|
+
}
|
|
5840
|
+
|
|
5771
5841
|
// src/populate-store.ts
|
|
5772
5842
|
import { useEffect as useEffect8 } from "react";
|
|
5773
5843
|
import { __dispatch as dispatch4 } from "@elementor/store";
|
|
@@ -5999,6 +6069,9 @@ function init() {
|
|
|
5999
6069
|
if (!!window.elementorPro && !isProAtLeast(PRO_EXTENDED_MIGRATION_VERSION)) {
|
|
6000
6070
|
initExtended();
|
|
6001
6071
|
}
|
|
6072
|
+
if (!!window.elementorPro) {
|
|
6073
|
+
initCreateComponentShortcut();
|
|
6074
|
+
}
|
|
6002
6075
|
}
|
|
6003
6076
|
export {
|
|
6004
6077
|
COMPONENT_WIDGET_TYPE,
|