@elementor/editor-components 3.33.0-234 → 3.33.0-236
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 +378 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +362 -77
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/components-tab/components-item.tsx +11 -2
- package/src/components/create-component-form/utils/replace-element-with-component.ts +3 -1
- package/src/components/edit-component/component-modal.tsx +134 -0
- package/src/components/edit-component/edit-component.tsx +119 -0
- package/src/create-component-type.ts +8 -2
- package/src/hooks/use-canvas-document.ts +6 -0
- package/src/hooks/use-element-rect.ts +81 -0
- package/src/init.ts +9 -2
- package/src/store/load-components-styles.ts +3 -3
- package/src/store/store.ts +9 -0
- package/src/types.ts +0 -11
package/dist/index.js
CHANGED
|
@@ -36,13 +36,13 @@ module.exports = __toCommonJS(index_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/init.ts
|
|
38
38
|
var import_editor = require("@elementor/editor");
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_editor_canvas5 = require("@elementor/editor-canvas");
|
|
40
|
+
var import_editor_documents2 = require("@elementor/editor-documents");
|
|
41
41
|
var import_editor_elements_panel = require("@elementor/editor-elements-panel");
|
|
42
42
|
var import_editor_styles_repository2 = require("@elementor/editor-styles-repository");
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
43
|
+
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
44
|
+
var import_store20 = require("@elementor/store");
|
|
45
|
+
var import_i18n8 = require("@wordpress/i18n");
|
|
46
46
|
|
|
47
47
|
// src/component-id-transformer.ts
|
|
48
48
|
var import_editor_canvas = require("@elementor/editor-canvas");
|
|
@@ -158,6 +158,14 @@ var selectUnpublishedComponents = (0, import_store2.__createSelector)(
|
|
|
158
158
|
selectUnpublishedData,
|
|
159
159
|
(unpublishedData) => unpublishedData
|
|
160
160
|
);
|
|
161
|
+
var selectComponentsObject = (0, import_store2.__createSelector)(
|
|
162
|
+
selectData,
|
|
163
|
+
selectUnpublishedData,
|
|
164
|
+
(data, unpublishedData) => data.concat(unpublishedData).reduce((acc, component) => {
|
|
165
|
+
acc[component.id] = component;
|
|
166
|
+
return acc;
|
|
167
|
+
}, {})
|
|
168
|
+
);
|
|
161
169
|
var selectLoadIsPending = (0, import_store2.__createSelector)(selectLoadStatus, (status) => status === "pending");
|
|
162
170
|
var selectLoadIsError = (0, import_store2.__createSelector)(selectLoadStatus, (status) => status === "error");
|
|
163
171
|
var selectStyles = (state) => state[SLICE_NAME].styles ?? {};
|
|
@@ -252,6 +260,58 @@ var import_editor_elements3 = require("@elementor/editor-elements");
|
|
|
252
260
|
var import_icons2 = require("@elementor/icons");
|
|
253
261
|
var import_ui2 = require("@elementor/ui");
|
|
254
262
|
|
|
263
|
+
// src/store/load-components-styles.ts
|
|
264
|
+
var import_store7 = require("@elementor/store");
|
|
265
|
+
|
|
266
|
+
// src/utils/get-component-ids.ts
|
|
267
|
+
var import_editor_props = require("@elementor/editor-props");
|
|
268
|
+
var getComponentIds = (elements) => {
|
|
269
|
+
return elements.flatMap((element) => {
|
|
270
|
+
const ids = [];
|
|
271
|
+
const type = element.widgetType || element.elType;
|
|
272
|
+
if (type === "e-component" && element.settings?.component && (0, import_editor_props.isTransformable)(element.settings?.component)) {
|
|
273
|
+
ids.push(element.settings.component.value);
|
|
274
|
+
}
|
|
275
|
+
if (element.elements) {
|
|
276
|
+
ids.push(...getComponentIds(element.elements));
|
|
277
|
+
}
|
|
278
|
+
return ids;
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/store/load-components-styles.ts
|
|
283
|
+
async function loadComponentsStyles(elements) {
|
|
284
|
+
const componentIds = Array.from(new Set(getComponentIds(elements)));
|
|
285
|
+
if (!componentIds.length) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const knownComponents = selectStyles((0, import_store7.__getState)());
|
|
289
|
+
const unknownComponentIds = componentIds.filter((id) => !knownComponents[id]);
|
|
290
|
+
if (!unknownComponentIds.length) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
addComponentStyles(unknownComponentIds);
|
|
294
|
+
}
|
|
295
|
+
async function addComponentStyles(ids) {
|
|
296
|
+
const newComponents = await loadStyles(ids);
|
|
297
|
+
addStyles(newComponents);
|
|
298
|
+
Object.values(newComponents).forEach(([, data]) => {
|
|
299
|
+
loadComponentsStyles(data.elements ?? []);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async function loadStyles(ids) {
|
|
303
|
+
return Promise.all(ids.map(async (id) => [id, await apiClient.getComponentConfig(id)]));
|
|
304
|
+
}
|
|
305
|
+
function addStyles(data) {
|
|
306
|
+
const styles = Object.fromEntries(
|
|
307
|
+
data.map(([componentId, componentData]) => [componentId, extractStyles(componentData)])
|
|
308
|
+
);
|
|
309
|
+
(0, import_store7.__dispatch)(slice.actions.addStyles(styles));
|
|
310
|
+
}
|
|
311
|
+
function extractStyles(element) {
|
|
312
|
+
return [...Object.values(element.styles ?? {}), ...(element.elements ?? []).flatMap(extractStyles)];
|
|
313
|
+
}
|
|
314
|
+
|
|
255
315
|
// src/utils/get-container-for-new-element.ts
|
|
256
316
|
var import_editor_elements = require("@elementor/editor-elements");
|
|
257
317
|
var getContainerForNewElement = () => {
|
|
@@ -319,12 +379,16 @@ var ComponentItem = ({ component }) => {
|
|
|
319
379
|
const handleClick = () => {
|
|
320
380
|
addComponentToPage(componentModel);
|
|
321
381
|
};
|
|
382
|
+
const handleDragEnd = () => {
|
|
383
|
+
loadComponentsStyles([componentModel]);
|
|
384
|
+
(0, import_editor_canvas2.endDragElementFromPanel)();
|
|
385
|
+
};
|
|
322
386
|
return /* @__PURE__ */ React3.createElement(
|
|
323
387
|
import_ui2.ListItemButton,
|
|
324
388
|
{
|
|
325
389
|
draggable: true,
|
|
326
390
|
onDragStart: () => (0, import_editor_canvas2.startDragElementFromPanel)(componentModel),
|
|
327
|
-
onDragEnd:
|
|
391
|
+
onDragEnd: handleDragEnd,
|
|
328
392
|
shape: "rounded",
|
|
329
393
|
sx: { border: "solid 1px", borderColor: "divider", py: 0.5, px: 1 }
|
|
330
394
|
},
|
|
@@ -341,6 +405,7 @@ var addComponentToPage = (model) => {
|
|
|
341
405
|
if (!container) {
|
|
342
406
|
throw new Error(`Can't find container to drop new component instance at`);
|
|
343
407
|
}
|
|
408
|
+
loadComponentsStyles([model]);
|
|
344
409
|
(0, import_editor_elements3.dropElement)({
|
|
345
410
|
containerId: container.id,
|
|
346
411
|
model,
|
|
@@ -510,7 +575,7 @@ var import_react3 = require("react");
|
|
|
510
575
|
var import_editor_elements4 = require("@elementor/editor-elements");
|
|
511
576
|
var import_editor_ui2 = require("@elementor/editor-ui");
|
|
512
577
|
var import_icons4 = require("@elementor/icons");
|
|
513
|
-
var
|
|
578
|
+
var import_store9 = require("@elementor/store");
|
|
514
579
|
var import_ui5 = require("@elementor/ui");
|
|
515
580
|
var import_i18n4 = require("@wordpress/i18n");
|
|
516
581
|
|
|
@@ -594,7 +659,7 @@ function CreateComponentForm() {
|
|
|
594
659
|
const [element, setElement] = (0, import_react3.useState)(null);
|
|
595
660
|
const [anchorPosition, setAnchorPosition] = (0, import_react3.useState)();
|
|
596
661
|
const [resultNotification, setResultNotification] = (0, import_react3.useState)(null);
|
|
597
|
-
const dispatch5 = (0,
|
|
662
|
+
const dispatch5 = (0, import_store9.__useDispatch)();
|
|
598
663
|
(0, import_react3.useEffect)(() => {
|
|
599
664
|
const OPEN_SAVE_AS_COMPONENT_FORM_EVENT = "elementor/editor/open-save-as-component-form";
|
|
600
665
|
const openPopup = (event) => {
|
|
@@ -733,29 +798,289 @@ var generateTempId = () => {
|
|
|
733
798
|
return Date.now() + Math.floor(Math.random() * 1e6);
|
|
734
799
|
};
|
|
735
800
|
|
|
736
|
-
// src/components/
|
|
801
|
+
// src/components/edit-component/edit-component.tsx
|
|
802
|
+
var React9 = __toESM(require("react"));
|
|
803
|
+
var import_react6 = require("react");
|
|
804
|
+
var import_editor_documents = require("@elementor/editor-documents");
|
|
805
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
806
|
+
var import_store11 = require("@elementor/store");
|
|
807
|
+
|
|
808
|
+
// src/components/edit-component/component-modal.tsx
|
|
737
809
|
var React8 = __toESM(require("react"));
|
|
810
|
+
var import_react5 = require("react");
|
|
811
|
+
var import_react_dom = require("react-dom");
|
|
812
|
+
var import_i18n5 = require("@wordpress/i18n");
|
|
813
|
+
|
|
814
|
+
// src/hooks/use-canvas-document.ts
|
|
815
|
+
var import_editor_canvas3 = require("@elementor/editor-canvas");
|
|
816
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
817
|
+
function useCanvasDocument() {
|
|
818
|
+
return (0, import_editor_v1_adapters2.__privateUseListenTo)((0, import_editor_v1_adapters2.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_canvas3.getCanvasIframeDocument)());
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// src/hooks/use-element-rect.ts
|
|
822
|
+
var import_react4 = require("react");
|
|
823
|
+
var import_utils2 = require("@elementor/utils");
|
|
824
|
+
function useElementRect(element) {
|
|
825
|
+
const [rect, setRect] = (0, import_react4.useState)(new DOMRect(0, 0, 0, 0));
|
|
826
|
+
const onChange = (0, import_utils2.throttle)(
|
|
827
|
+
() => {
|
|
828
|
+
setRect(element?.getBoundingClientRect() ?? new DOMRect(0, 0, 0, 0));
|
|
829
|
+
},
|
|
830
|
+
20,
|
|
831
|
+
true
|
|
832
|
+
);
|
|
833
|
+
useScrollListener({ element, onChange });
|
|
834
|
+
useResizeListener({ element, onChange });
|
|
835
|
+
useMutationsListener({ element, onChange });
|
|
836
|
+
(0, import_react4.useEffect)(
|
|
837
|
+
() => () => {
|
|
838
|
+
onChange.cancel();
|
|
839
|
+
},
|
|
840
|
+
[onChange]
|
|
841
|
+
);
|
|
842
|
+
return rect;
|
|
843
|
+
}
|
|
844
|
+
function useScrollListener({ element, onChange }) {
|
|
845
|
+
(0, import_react4.useEffect)(() => {
|
|
846
|
+
if (!element) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const win = element.ownerDocument?.defaultView;
|
|
850
|
+
win?.addEventListener("scroll", onChange, { passive: true });
|
|
851
|
+
return () => {
|
|
852
|
+
win?.removeEventListener("scroll", onChange);
|
|
853
|
+
};
|
|
854
|
+
}, [element, onChange]);
|
|
855
|
+
}
|
|
856
|
+
function useResizeListener({ element, onChange }) {
|
|
857
|
+
(0, import_react4.useEffect)(() => {
|
|
858
|
+
if (!element) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const resizeObserver = new ResizeObserver(onChange);
|
|
862
|
+
resizeObserver.observe(element);
|
|
863
|
+
const win = element.ownerDocument?.defaultView;
|
|
864
|
+
win?.addEventListener("resize", onChange, { passive: true });
|
|
865
|
+
return () => {
|
|
866
|
+
resizeObserver.disconnect();
|
|
867
|
+
win?.removeEventListener("resize", onChange);
|
|
868
|
+
};
|
|
869
|
+
}, [element, onChange]);
|
|
870
|
+
}
|
|
871
|
+
function useMutationsListener({ element, onChange }) {
|
|
872
|
+
(0, import_react4.useEffect)(() => {
|
|
873
|
+
if (!element) {
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const mutationObserver = new MutationObserver(onChange);
|
|
877
|
+
mutationObserver.observe(element, { childList: true, subtree: true });
|
|
878
|
+
return () => {
|
|
879
|
+
mutationObserver.disconnect();
|
|
880
|
+
};
|
|
881
|
+
}, [element, onChange]);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// src/components/edit-component/component-modal.tsx
|
|
885
|
+
function ComponentModal({ element, onClose }) {
|
|
886
|
+
const canvasDocument = useCanvasDocument();
|
|
887
|
+
(0, import_react5.useEffect)(() => {
|
|
888
|
+
const handleEsc = (event) => {
|
|
889
|
+
if (event.key === "Escape") {
|
|
890
|
+
onClose();
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
canvasDocument?.body.addEventListener("keydown", handleEsc);
|
|
894
|
+
return () => {
|
|
895
|
+
canvasDocument?.body.removeEventListener("keydown", handleEsc);
|
|
896
|
+
};
|
|
897
|
+
}, [canvasDocument, onClose]);
|
|
898
|
+
if (!canvasDocument?.body) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
return (0, import_react_dom.createPortal)(
|
|
902
|
+
/* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement(BlockEditPage, null), /* @__PURE__ */ React8.createElement(Backdrop, { canvas: canvasDocument, element, onClose })),
|
|
903
|
+
canvasDocument.body
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
function Backdrop({ canvas, element, onClose }) {
|
|
907
|
+
const rect = useElementRect(element);
|
|
908
|
+
const backdropStyle = {
|
|
909
|
+
position: "fixed",
|
|
910
|
+
top: 0,
|
|
911
|
+
left: 0,
|
|
912
|
+
width: "100vw",
|
|
913
|
+
height: "100vh",
|
|
914
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
915
|
+
zIndex: 999,
|
|
916
|
+
pointerEvents: "painted",
|
|
917
|
+
cursor: "pointer",
|
|
918
|
+
clipPath: getRoundedRectPath(rect, canvas.defaultView, 5)
|
|
919
|
+
};
|
|
920
|
+
const handleKeyDown = (event) => {
|
|
921
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
922
|
+
event.preventDefault();
|
|
923
|
+
onClose();
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
return /* @__PURE__ */ React8.createElement(
|
|
927
|
+
"div",
|
|
928
|
+
{
|
|
929
|
+
style: backdropStyle,
|
|
930
|
+
onClick: onClose,
|
|
931
|
+
onKeyDown: handleKeyDown,
|
|
932
|
+
role: "button",
|
|
933
|
+
tabIndex: 0,
|
|
934
|
+
"aria-label": (0, import_i18n5.__)("Exit component editing mode", "elementor")
|
|
935
|
+
}
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
function getRoundedRectPath(rect, viewport, borderRadius) {
|
|
939
|
+
const padding = borderRadius / 2;
|
|
940
|
+
const { x: originalX, y: originalY, width: originalWidth, height: originalHeight } = rect;
|
|
941
|
+
const x = originalX - padding;
|
|
942
|
+
const y = originalY - padding;
|
|
943
|
+
const width = originalWidth + 2 * padding;
|
|
944
|
+
const height = originalHeight + 2 * padding;
|
|
945
|
+
const radius = Math.min(borderRadius, width / 2, height / 2);
|
|
946
|
+
const { innerWidth: vw, innerHeight: vh } = viewport;
|
|
947
|
+
const path = `path(evenodd, 'M 0 0
|
|
948
|
+
L ${vw} 0
|
|
949
|
+
L ${vw} ${vh}
|
|
950
|
+
L 0 ${vh}
|
|
951
|
+
Z
|
|
952
|
+
M ${x + radius} ${y}
|
|
953
|
+
L ${x + width - radius} ${y}
|
|
954
|
+
A ${radius} ${radius} 0 0 1 ${x + width} ${y + radius}
|
|
955
|
+
L ${x + width} ${y + height - radius}
|
|
956
|
+
A ${radius} ${radius} 0 0 1 ${x + width - radius} ${y + height}
|
|
957
|
+
L ${x + radius} ${y + height}
|
|
958
|
+
A ${radius} ${radius} 0 0 1 ${x} ${y + height - radius}
|
|
959
|
+
L ${x} ${y + radius}
|
|
960
|
+
A ${radius} ${radius} 0 0 1 ${x + radius} ${y}
|
|
961
|
+
Z'
|
|
962
|
+
)`;
|
|
963
|
+
return path.replace(/\s{2,}/g, " ");
|
|
964
|
+
}
|
|
965
|
+
function BlockEditPage() {
|
|
966
|
+
const blockV3DocumentHandlesStyles = `
|
|
967
|
+
.elementor-editor-active {
|
|
968
|
+
& .elementor-section-wrap.ui-sortable {
|
|
969
|
+
display: contents;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
& *[data-editable-elementor-document]:not(.elementor-edit-mode):hover {
|
|
973
|
+
& .elementor-document-handle:not(.elementor-document-save-back-handle) {
|
|
974
|
+
display: none;
|
|
975
|
+
|
|
976
|
+
&::before,
|
|
977
|
+
& .elementor-document-handle__inner {
|
|
978
|
+
display: none;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
`;
|
|
984
|
+
return /* @__PURE__ */ React8.createElement("style", { "data-e-style-id": "e-block-v3-document-handles-styles" }, blockV3DocumentHandlesStyles);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/components/edit-component/edit-component.tsx
|
|
988
|
+
function EditComponent() {
|
|
989
|
+
const [componentsPath, setComponentsPath] = (0, import_react6.useState)([]);
|
|
990
|
+
useHandleDocumentSwitches(componentsPath, setComponentsPath);
|
|
991
|
+
const onBack = useNavigateBack(componentsPath);
|
|
992
|
+
const currentItem = componentsPath.at(-1);
|
|
993
|
+
const { component: currentComponent } = currentItem ?? {};
|
|
994
|
+
const widget = currentComponent?.container;
|
|
995
|
+
const container = widget?.view?.el?.children?.[0] ?? null;
|
|
996
|
+
const elementDom = container?.children[0];
|
|
997
|
+
if (!elementDom) {
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
return /* @__PURE__ */ React9.createElement(ComponentModal, { element: elementDom, onClose: onBack });
|
|
1001
|
+
}
|
|
1002
|
+
function useHandleDocumentSwitches(path, setPath) {
|
|
1003
|
+
const components = (0, import_store11.__useSelector)(selectComponentsObject);
|
|
1004
|
+
const documentsManager = (0, import_editor_documents.getV1DocumentsManager)();
|
|
1005
|
+
(0, import_react6.useEffect)(
|
|
1006
|
+
() => (0, import_editor_v1_adapters3.__privateListenTo)((0, import_editor_v1_adapters3.commandEndEvent)("editor/documents/attach-preview"), () => {
|
|
1007
|
+
const { component: currentComponent } = path.at(-1) ?? {};
|
|
1008
|
+
const { id: currentComponentId } = currentComponent ?? {};
|
|
1009
|
+
const nextDocument = documentsManager.getCurrent();
|
|
1010
|
+
if (nextDocument.id === currentComponentId) {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (currentComponentId) {
|
|
1014
|
+
apiClient.unlockComponent(currentComponentId);
|
|
1015
|
+
}
|
|
1016
|
+
const isComponent = !!components?.[nextDocument.id];
|
|
1017
|
+
if (!isComponent) {
|
|
1018
|
+
setPath([]);
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
setPath(getUpdatedComponentPath(path, nextDocument));
|
|
1022
|
+
}),
|
|
1023
|
+
[path, setPath, components, documentsManager]
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
function getUpdatedComponentPath(path, nextDocument) {
|
|
1027
|
+
const componentIndex = path.findIndex(({ component }) => component.id === nextDocument.id);
|
|
1028
|
+
if (componentIndex >= 0) {
|
|
1029
|
+
return path.slice(0, componentIndex + 1);
|
|
1030
|
+
}
|
|
1031
|
+
return [
|
|
1032
|
+
...path,
|
|
1033
|
+
{
|
|
1034
|
+
instanceId: nextDocument?.container.view?.el?.dataset.id,
|
|
1035
|
+
component: nextDocument
|
|
1036
|
+
}
|
|
1037
|
+
];
|
|
1038
|
+
}
|
|
1039
|
+
function useNavigateBack(path) {
|
|
1040
|
+
const documentsManager = (0, import_editor_documents.getV1DocumentsManager)();
|
|
1041
|
+
return (0, import_react6.useCallback)(() => {
|
|
1042
|
+
const { component: prevComponent, instanceId: prevComponentInstanceId } = path.at(-2) ?? {};
|
|
1043
|
+
const { id: prevComponentId } = prevComponent ?? {};
|
|
1044
|
+
const switchToDocument = (id, selector) => {
|
|
1045
|
+
(0, import_editor_v1_adapters3.__privateRunCommand)("editor/documents/switch", {
|
|
1046
|
+
id,
|
|
1047
|
+
selector,
|
|
1048
|
+
mode: "autosave",
|
|
1049
|
+
setAsInitial: false,
|
|
1050
|
+
shouldScroll: false
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
if (prevComponentId && prevComponentInstanceId) {
|
|
1054
|
+
switchToDocument(prevComponentId, `[data-id="${prevComponentInstanceId}"]`);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
switchToDocument(documentsManager.getInitialId());
|
|
1058
|
+
}, [path, documentsManager]);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// src/components/in-edit-mode.tsx
|
|
1062
|
+
var React10 = __toESM(require("react"));
|
|
738
1063
|
var import_editor_ui3 = require("@elementor/editor-ui");
|
|
739
1064
|
var import_icons5 = require("@elementor/icons");
|
|
740
1065
|
var import_ui6 = require("@elementor/ui");
|
|
741
|
-
var
|
|
1066
|
+
var import_i18n6 = require("@wordpress/i18n");
|
|
742
1067
|
var openEditModeDialog = (lockedBy) => {
|
|
743
1068
|
(0, import_editor_ui3.openDialog)({
|
|
744
|
-
component: /* @__PURE__ */
|
|
1069
|
+
component: /* @__PURE__ */ React10.createElement(EditModeDialog, { lockedBy })
|
|
745
1070
|
});
|
|
746
1071
|
};
|
|
747
1072
|
var EditModeDialog = ({ lockedBy }) => {
|
|
748
|
-
const content = (0,
|
|
749
|
-
return /* @__PURE__ */
|
|
1073
|
+
const content = (0, import_i18n6.__)("%s is currently editing this document", "elementor").replace("%s", lockedBy);
|
|
1074
|
+
return /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(import_ui6.DialogHeader, { logo: false }, /* @__PURE__ */ React10.createElement(import_ui6.Box, { display: "flex", alignItems: "center", gap: 1 }, /* @__PURE__ */ React10.createElement(import_ui6.Icon, { color: "secondary" }, /* @__PURE__ */ React10.createElement(import_icons5.InfoCircleFilledIcon, { fontSize: "medium" })), /* @__PURE__ */ React10.createElement(import_ui6.Typography, { variant: "subtitle1" }, content))), /* @__PURE__ */ React10.createElement(import_ui6.DialogContent, null, /* @__PURE__ */ React10.createElement(import_ui6.Stack, { spacing: 2, direction: "column" }, /* @__PURE__ */ React10.createElement(import_ui6.Typography, { variant: "body2" }, (0, import_i18n6.__)(
|
|
750
1075
|
"You can wait for them to finish or reach out to coordinate your changes together.",
|
|
751
1076
|
"elementor"
|
|
752
|
-
)), /* @__PURE__ */
|
|
1077
|
+
)), /* @__PURE__ */ React10.createElement(import_ui6.DialogActions, null, /* @__PURE__ */ React10.createElement(import_ui6.Button, { color: "secondary", variant: "contained", onClick: import_editor_ui3.closeDialog }, (0, import_i18n6.__)("Close", "elementor"))))));
|
|
753
1078
|
};
|
|
754
1079
|
|
|
755
1080
|
// src/create-component-type.ts
|
|
756
|
-
var
|
|
757
|
-
var
|
|
758
|
-
var
|
|
1081
|
+
var import_editor_canvas4 = require("@elementor/editor-canvas");
|
|
1082
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
1083
|
+
var import_i18n7 = require("@wordpress/i18n");
|
|
759
1084
|
var TYPE = "e-component";
|
|
760
1085
|
function createComponentType(options) {
|
|
761
1086
|
const legacyWindow = window;
|
|
@@ -769,7 +1094,7 @@ function createComponentType(options) {
|
|
|
769
1094
|
};
|
|
770
1095
|
}
|
|
771
1096
|
function createComponentView(options) {
|
|
772
|
-
return class extends (0,
|
|
1097
|
+
return class extends (0, import_editor_canvas4.createTemplatedElementView)(options) {
|
|
773
1098
|
legacyWindow = window;
|
|
774
1099
|
afterSettingsResolve(settings) {
|
|
775
1100
|
if (settings.component) {
|
|
@@ -806,7 +1131,7 @@ function createComponentView(options) {
|
|
|
806
1131
|
{
|
|
807
1132
|
name: "edit component",
|
|
808
1133
|
icon: "eicon-edit",
|
|
809
|
-
title: () => (0,
|
|
1134
|
+
title: () => (0, import_i18n7.__)("Edit Component", "elementor"),
|
|
810
1135
|
isEnabled: () => true,
|
|
811
1136
|
callback: () => this.switchDocument()
|
|
812
1137
|
}
|
|
@@ -822,18 +1147,22 @@ function createComponentView(options) {
|
|
|
822
1147
|
if (!isAllowedToSwitchDocument) {
|
|
823
1148
|
options.showLockedByModal?.(lockedBy || "");
|
|
824
1149
|
} else {
|
|
825
|
-
(0,
|
|
1150
|
+
(0, import_editor_v1_adapters4.__privateRunCommand)("editor/documents/switch", {
|
|
826
1151
|
id: this.getComponentId()?.value,
|
|
827
1152
|
mode: "autosave",
|
|
828
|
-
selector: `[data-id="${this.model.get("id")}"]
|
|
1153
|
+
selector: `[data-id="${this.model.get("id")}"]`,
|
|
1154
|
+
shouldScroll: false
|
|
829
1155
|
});
|
|
830
|
-
apiClient.lockComponent(this.getComponentId()?.value);
|
|
831
1156
|
}
|
|
832
1157
|
}
|
|
1158
|
+
handleDblClick(e) {
|
|
1159
|
+
e.stopPropagation();
|
|
1160
|
+
this.switchDocument();
|
|
1161
|
+
}
|
|
833
1162
|
events() {
|
|
834
1163
|
return {
|
|
835
1164
|
...super.events(),
|
|
836
|
-
dblclick: this.
|
|
1165
|
+
dblclick: this.handleDblClick
|
|
837
1166
|
};
|
|
838
1167
|
}
|
|
839
1168
|
attributes() {
|
|
@@ -858,22 +1187,22 @@ function setInactiveRecursively(model) {
|
|
|
858
1187
|
}
|
|
859
1188
|
|
|
860
1189
|
// src/populate-store.ts
|
|
861
|
-
var
|
|
862
|
-
var
|
|
1190
|
+
var import_react7 = require("react");
|
|
1191
|
+
var import_store13 = require("@elementor/store");
|
|
863
1192
|
function PopulateStore() {
|
|
864
|
-
(0,
|
|
865
|
-
(0,
|
|
1193
|
+
(0, import_react7.useEffect)(() => {
|
|
1194
|
+
(0, import_store13.__dispatch)(loadComponents());
|
|
866
1195
|
}, []);
|
|
867
1196
|
return null;
|
|
868
1197
|
}
|
|
869
1198
|
|
|
870
1199
|
// src/store/components-styles-provider.ts
|
|
871
1200
|
var import_editor_styles_repository = require("@elementor/editor-styles-repository");
|
|
872
|
-
var
|
|
1201
|
+
var import_store14 = require("@elementor/store");
|
|
873
1202
|
var componentsStylesProvider = (0, import_editor_styles_repository.createStylesProvider)({
|
|
874
1203
|
key: "components-styles",
|
|
875
1204
|
priority: 100,
|
|
876
|
-
subscribe: (cb) => (0,
|
|
1205
|
+
subscribe: (cb) => (0, import_store14.__subscribeWithSelector)(
|
|
877
1206
|
(state) => state[SLICE_NAME],
|
|
878
1207
|
() => {
|
|
879
1208
|
cb();
|
|
@@ -881,78 +1210,26 @@ var componentsStylesProvider = (0, import_editor_styles_repository.createStylesP
|
|
|
881
1210
|
),
|
|
882
1211
|
actions: {
|
|
883
1212
|
all: () => {
|
|
884
|
-
return selectFlatStyles((0,
|
|
1213
|
+
return selectFlatStyles((0, import_store14.__getState)());
|
|
885
1214
|
},
|
|
886
1215
|
get: (id) => {
|
|
887
|
-
return selectFlatStyles((0,
|
|
1216
|
+
return selectFlatStyles((0, import_store14.__getState)()).find((style) => style.id === id) ?? null;
|
|
888
1217
|
}
|
|
889
1218
|
}
|
|
890
1219
|
});
|
|
891
1220
|
|
|
892
|
-
// src/store/load-components-styles.ts
|
|
893
|
-
var import_store12 = require("@elementor/store");
|
|
894
|
-
|
|
895
|
-
// src/utils/get-component-ids.ts
|
|
896
|
-
var import_editor_props = require("@elementor/editor-props");
|
|
897
|
-
var getComponentIds = (elements) => {
|
|
898
|
-
return elements.flatMap((element) => {
|
|
899
|
-
const ids = [];
|
|
900
|
-
const type = element.widgetType || element.elType;
|
|
901
|
-
if (type === "e-component" && element.settings?.component && (0, import_editor_props.isTransformable)(element.settings?.component)) {
|
|
902
|
-
ids.push(element.settings.component.value);
|
|
903
|
-
}
|
|
904
|
-
if (element.elements) {
|
|
905
|
-
ids.push(...getComponentIds(element.elements));
|
|
906
|
-
}
|
|
907
|
-
return ids;
|
|
908
|
-
});
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
// src/store/load-components-styles.ts
|
|
912
|
-
async function loadComponentsStyles(elements) {
|
|
913
|
-
const componentIds = Array.from(new Set(getComponentIds(elements)));
|
|
914
|
-
if (!componentIds.length) {
|
|
915
|
-
return;
|
|
916
|
-
}
|
|
917
|
-
const knownComponents = selectStyles((0, import_store12.__getState)());
|
|
918
|
-
const unknownComponentIds = componentIds.filter((id) => !knownComponents[id]);
|
|
919
|
-
if (!unknownComponentIds.length) {
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
addComponentStyles(unknownComponentIds);
|
|
923
|
-
}
|
|
924
|
-
async function addComponentStyles(ids) {
|
|
925
|
-
const newComponents = await loadStyles(ids);
|
|
926
|
-
addStyles(newComponents);
|
|
927
|
-
Object.values(newComponents).forEach(([, data]) => {
|
|
928
|
-
loadComponentsStyles(data.elements);
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
async function loadStyles(ids) {
|
|
932
|
-
return Promise.all(ids.map(async (id) => [id, await apiClient.getComponentConfig(id)]));
|
|
933
|
-
}
|
|
934
|
-
function addStyles(data) {
|
|
935
|
-
const styles = Object.fromEntries(
|
|
936
|
-
data.map(([componentId, componentData]) => [componentId, extractStyles(componentData)])
|
|
937
|
-
);
|
|
938
|
-
(0, import_store12.__dispatch)(slice.actions.addStyles(styles));
|
|
939
|
-
}
|
|
940
|
-
function extractStyles(element) {
|
|
941
|
-
return [...Object.values(element.styles ?? {}), ...(element.elements ?? []).flatMap(extractStyles)];
|
|
942
|
-
}
|
|
943
|
-
|
|
944
1221
|
// src/store/remove-component-styles.ts
|
|
945
|
-
var
|
|
1222
|
+
var import_store16 = require("@elementor/store");
|
|
946
1223
|
function removeComponentStyles(id) {
|
|
947
1224
|
apiClient.invalidateComponentConfigCache(id);
|
|
948
|
-
(0,
|
|
1225
|
+
(0, import_store16.__dispatch)(slice.actions.removeStyles({ id }));
|
|
949
1226
|
}
|
|
950
1227
|
|
|
951
1228
|
// src/utils/before-save.ts
|
|
952
1229
|
var import_editor_elements5 = require("@elementor/editor-elements");
|
|
953
|
-
var
|
|
1230
|
+
var import_store18 = require("@elementor/store");
|
|
954
1231
|
var beforeSave = async ({ container, status }) => {
|
|
955
|
-
const unpublishedComponents = selectUnpublishedComponents((0,
|
|
1232
|
+
const unpublishedComponents = selectUnpublishedComponents((0, import_store18.__getState)());
|
|
956
1233
|
if (!unpublishedComponents.length) {
|
|
957
1234
|
return;
|
|
958
1235
|
}
|
|
@@ -960,7 +1237,7 @@ var beforeSave = async ({ container, status }) => {
|
|
|
960
1237
|
const tempIdToComponentId = await createComponents(unpublishedComponents, status);
|
|
961
1238
|
const elements = container.model.get("elements").toJSON();
|
|
962
1239
|
updateComponentInstances(elements, tempIdToComponentId);
|
|
963
|
-
(0,
|
|
1240
|
+
(0, import_store18.__dispatch)(
|
|
964
1241
|
slice.actions.add(
|
|
965
1242
|
unpublishedComponents.map((component) => ({
|
|
966
1243
|
id: tempIdToComponentId.get(component.id),
|
|
@@ -968,7 +1245,7 @@ var beforeSave = async ({ container, status }) => {
|
|
|
968
1245
|
}))
|
|
969
1246
|
)
|
|
970
1247
|
);
|
|
971
|
-
(0,
|
|
1248
|
+
(0, import_store18.__dispatch)(slice.actions.resetUnpublished());
|
|
972
1249
|
} catch (error) {
|
|
973
1250
|
throw new Error(`Failed to publish components and update component instances: ${error}`);
|
|
974
1251
|
}
|
|
@@ -1025,13 +1302,13 @@ function updateElementComponentId(elementId, componentId) {
|
|
|
1025
1302
|
var COMPONENT_DOCUMENT_TYPE = "elementor_component";
|
|
1026
1303
|
function init() {
|
|
1027
1304
|
import_editor_styles_repository2.stylesRepository.register(componentsStylesProvider);
|
|
1028
|
-
(0,
|
|
1029
|
-
(0,
|
|
1305
|
+
(0, import_store20.__registerSlice)(slice);
|
|
1306
|
+
(0, import_editor_canvas5.registerElementType)(
|
|
1030
1307
|
TYPE,
|
|
1031
1308
|
(options) => createComponentType({ ...options, showLockedByModal: openEditModeDialog })
|
|
1032
1309
|
);
|
|
1033
|
-
(0,
|
|
1034
|
-
const document = (0,
|
|
1310
|
+
(0, import_editor_v1_adapters5.registerDataHook)("dependency", "editor/documents/close", (args) => {
|
|
1311
|
+
const document = (0, import_editor_documents2.getV1CurrentDocument)();
|
|
1035
1312
|
if (document.config.type === COMPONENT_DOCUMENT_TYPE) {
|
|
1036
1313
|
args.mode = "autosave";
|
|
1037
1314
|
}
|
|
@@ -1040,7 +1317,7 @@ function init() {
|
|
|
1040
1317
|
window.elementorCommon.__beforeSave = beforeSave;
|
|
1041
1318
|
(0, import_editor_elements_panel.injectTab)({
|
|
1042
1319
|
id: "components",
|
|
1043
|
-
label: (0,
|
|
1320
|
+
label: (0, import_i18n8.__)("Components", "elementor"),
|
|
1044
1321
|
component: Components
|
|
1045
1322
|
});
|
|
1046
1323
|
(0, import_editor.injectIntoTop)({
|
|
@@ -1051,14 +1328,18 @@ function init() {
|
|
|
1051
1328
|
id: "components-populate-store",
|
|
1052
1329
|
component: PopulateStore
|
|
1053
1330
|
});
|
|
1054
|
-
(0,
|
|
1055
|
-
|
|
1331
|
+
(0, import_editor.injectIntoTop)({
|
|
1332
|
+
id: "edit-component",
|
|
1333
|
+
component: EditComponent
|
|
1334
|
+
});
|
|
1335
|
+
(0, import_editor_v1_adapters5.__privateListenTo)((0, import_editor_v1_adapters5.commandStartEvent)("editor/documents/attach-preview"), () => {
|
|
1336
|
+
const { id, config } = (0, import_editor_documents2.getV1CurrentDocument)();
|
|
1056
1337
|
if (id) {
|
|
1057
1338
|
removeComponentStyles(id);
|
|
1058
1339
|
}
|
|
1059
1340
|
loadComponentsStyles(config?.elements ?? []);
|
|
1060
1341
|
});
|
|
1061
|
-
|
|
1342
|
+
import_editor_canvas5.settingsTransformersRegistry.register("component-id", componentIdTransformer);
|
|
1062
1343
|
}
|
|
1063
1344
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1064
1345
|
0 && (module.exports = {
|