@elementor/editor-components 3.33.0-252 → 3.33.0-254

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.mjs CHANGED
@@ -72,7 +72,8 @@ var initialState = {
72
72
  data: [],
73
73
  unpublishedData: [],
74
74
  loadStatus: "idle",
75
- styles: {}
75
+ styles: {},
76
+ createdThisSession: []
76
77
  };
77
78
  var SLICE_NAME = "components";
78
79
  var slice = createSlice({
@@ -101,6 +102,9 @@ var slice = createSlice({
101
102
  },
102
103
  addStyles: (state, { payload }) => {
103
104
  state.styles = { ...state.styles, ...payload };
105
+ },
106
+ addCreatedThisSession: (state, { payload }) => {
107
+ state.createdThisSession.push(payload);
104
108
  }
105
109
  },
106
110
  extraReducers: (builder) => {
@@ -120,11 +124,12 @@ var selectData = (state) => state[SLICE_NAME].data;
120
124
  var selectLoadStatus = (state) => state[SLICE_NAME].loadStatus;
121
125
  var selectStylesDefinitions = (state) => state[SLICE_NAME].styles ?? {};
122
126
  var selectUnpublishedData = (state) => state[SLICE_NAME].unpublishedData;
127
+ var getCreatedThisSession = (state) => state[SLICE_NAME].createdThisSession;
123
128
  var selectComponents = createSelector(
124
129
  selectData,
125
130
  selectUnpublishedData,
126
131
  (data, unpublishedData) => [
127
- ...unpublishedData.map((item) => ({ id: item.id, name: item.name })),
132
+ ...unpublishedData.map((item) => ({ uid: item.uid, name: item.name })),
128
133
  ...data
129
134
  ]
130
135
  );
@@ -132,18 +137,14 @@ var selectUnpublishedComponents = createSelector(
132
137
  selectUnpublishedData,
133
138
  (unpublishedData) => unpublishedData
134
139
  );
135
- var selectComponentsObject = createSelector(
136
- selectData,
137
- selectUnpublishedData,
138
- (data, unpublishedData) => data.concat(unpublishedData).reduce((acc, component) => {
139
- acc[component.id] = component;
140
- return acc;
141
- }, {})
142
- );
143
140
  var selectLoadIsPending = createSelector(selectLoadStatus, (status) => status === "pending");
144
141
  var selectLoadIsError = createSelector(selectLoadStatus, (status) => status === "error");
145
142
  var selectStyles = (state) => state[SLICE_NAME].styles ?? {};
146
143
  var selectFlatStyles = createSelector(selectStylesDefinitions, (data) => Object.values(data).flat());
144
+ var selectCreatedThisSession = createSelector(
145
+ getCreatedThisSession,
146
+ (createdThisSession) => createdThisSession
147
+ );
147
148
 
148
149
  // src/utils/component-document-data.ts
149
150
  var getComponentDocumentData = async (id) => {
@@ -168,15 +169,20 @@ function getDocumentsManager() {
168
169
  }
169
170
 
170
171
  // src/component-id-transformer.ts
171
- var componentIdTransformer = createTransformer(async (id) => {
172
- const unpublishedComponents = selectUnpublishedComponents(getState());
173
- const unpublishedComponent = unpublishedComponents.find((component) => component.id === id);
174
- if (unpublishedComponent) {
175
- return structuredClone(unpublishedComponent.elements);
172
+ var componentIdTransformer = createTransformer(
173
+ async (id) => {
174
+ const unpublishedComponents = selectUnpublishedComponents(getState());
175
+ const unpublishedComponent = unpublishedComponents.find(({ uid }) => uid === id);
176
+ if (unpublishedComponent) {
177
+ return structuredClone(unpublishedComponent.elements);
178
+ }
179
+ if (typeof id !== "number") {
180
+ throw new Error(`Component ID "${id}" not found.`);
181
+ }
182
+ const data = await getComponentDocumentData(id);
183
+ return data?.elements ?? [];
176
184
  }
177
- const data = await getComponentDocumentData(id);
178
- return data?.elements ?? [];
179
- });
185
+ );
180
186
 
181
187
  // src/components/components-tab/components.tsx
182
188
  import * as React6 from "react";
@@ -360,18 +366,19 @@ var createComponentModel = (component) => {
360
366
  settings: {
361
367
  component: {
362
368
  $$type: "component-id",
363
- value: component.id
369
+ value: component.id ?? component.uid
364
370
  }
365
371
  },
366
372
  editor_settings: {
367
- title: component.name
373
+ title: component.name,
374
+ component_uid: component.uid
368
375
  }
369
376
  };
370
377
  };
371
378
 
372
379
  // src/components/components-tab/components-item.tsx
373
380
  var ComponentItem = ({ component }) => {
374
- const componentModel = createComponentModel({ id: component.id, name: component.name });
381
+ const componentModel = createComponentModel(component);
375
382
  const handleClick = () => {
376
383
  addComponentToPage(componentModel);
377
384
  };
@@ -462,7 +469,7 @@ function ComponentsList() {
462
469
  }
463
470
  return /* @__PURE__ */ React5.createElement(EmptyState, null);
464
471
  }
465
- return /* @__PURE__ */ React5.createElement(List, { sx: { display: "flex", flexDirection: "column", gap: 1, px: 2 } }, components.map((component) => /* @__PURE__ */ React5.createElement(ComponentItem, { key: component.id, component })));
472
+ return /* @__PURE__ */ React5.createElement(List, { sx: { display: "flex", flexDirection: "column", gap: 1, px: 2 } }, components.map((component) => /* @__PURE__ */ React5.createElement(ComponentItem, { key: component.uid, component })));
466
473
  }
467
474
  var EmptyState = () => {
468
475
  return /* @__PURE__ */ React5.createElement(
@@ -573,6 +580,7 @@ import { ThemeProvider as ThemeProvider2 } from "@elementor/editor-ui";
573
580
  import { StarIcon } from "@elementor/icons";
574
581
  import { __useDispatch as useDispatch } from "@elementor/store";
575
582
  import { Alert, Button, FormLabel, Grid, Popover, Snackbar, Stack as Stack4, TextField as TextField2, Typography as Typography3 } from "@elementor/ui";
583
+ import { generateUniqueId } from "@elementor/utils";
576
584
  import { __ as __4 } from "@wordpress/i18n";
577
585
 
578
586
  // src/components/create-component-form/hooks/use-form.ts
@@ -667,27 +675,25 @@ function CreateComponentForm() {
667
675
  window.removeEventListener(OPEN_SAVE_AS_COMPONENT_FORM_EVENT, openPopup);
668
676
  };
669
677
  }, []);
670
- const handleSave = async (values) => {
678
+ const handleSave = (values) => {
671
679
  try {
672
680
  if (!element) {
673
681
  throw new Error(`Can't save element as component: element not found`);
674
682
  }
675
- const tempId = generateTempId();
683
+ const uid = generateUniqueId("component");
676
684
  dispatch5(
677
685
  slice.actions.addUnpublished({
678
- id: tempId,
686
+ uid,
679
687
  name: values.componentName,
680
688
  elements: [element.element.model.toJSON({ remove: ["default"] })]
681
689
  })
682
690
  );
683
- replaceElementWithComponent(element.element, {
684
- id: tempId,
685
- name: values.componentName
686
- });
691
+ dispatch5(slice.actions.addCreatedThisSession(uid));
692
+ replaceElementWithComponent(element.element, { uid, name: values.componentName });
687
693
  setResultNotification({
688
694
  show: true,
689
- // Translators: %1$s: Component name, %2$s: Component temp ID
690
- message: __4("Component saved successfully as: %1$s (temp ID: %2$s)", "elementor").replace("%1$s", values.componentName).replace("%2$s", tempId.toString()),
695
+ // Translators: %1$s: Component name, %2$s: Component UID
696
+ message: __4("Component saved successfully as: %1$s (UID: %2$s)", "elementor").replace("%1$s", values.componentName).replace("%2$s", uid),
691
697
  type: "success"
692
698
  });
693
699
  resetAndClosePopup();
@@ -704,11 +710,14 @@ function CreateComponentForm() {
704
710
  setElement(null);
705
711
  setAnchorPosition(void 0);
706
712
  };
713
+ const cancelSave = () => {
714
+ resetAndClosePopup();
715
+ };
707
716
  return /* @__PURE__ */ React7.createElement(ThemeProvider2, null, /* @__PURE__ */ React7.createElement(
708
717
  Popover,
709
718
  {
710
719
  open: element !== null,
711
- onClose: resetAndClosePopup,
720
+ onClose: cancelSave,
712
721
  anchorReference: "anchorPosition",
713
722
  anchorPosition
714
723
  },
@@ -717,7 +726,7 @@ function CreateComponentForm() {
717
726
  {
718
727
  initialValues: { componentName: element.elementLabel },
719
728
  handleSave,
720
- closePopup: resetAndClosePopup
729
+ closePopup: cancelSave
721
730
  }
722
731
  )
723
732
  ), /* @__PURE__ */ React7.createElement(Snackbar, { open: resultNotification?.show, onClose: () => setResultNotification(null) }, /* @__PURE__ */ React7.createElement(
@@ -790,9 +799,6 @@ var Form = ({
790
799
  __4("Create", "elementor")
791
800
  )));
792
801
  };
793
- var generateTempId = () => {
794
- return Date.now() + Math.floor(Math.random() * 1e6);
795
- };
796
802
 
797
803
  // src/components/edit-component/edit-component.tsx
798
804
  import * as React9 from "react";
@@ -803,7 +809,9 @@ import {
803
809
  __privateRunCommand as runCommand,
804
810
  commandEndEvent as commandEndEvent2
805
811
  } from "@elementor/editor-v1-adapters";
806
- import { __useSelector as useSelector2 } from "@elementor/store";
812
+
813
+ // src/components/consts.ts
814
+ var COMPONENT_DOCUMENT_TYPE = "elementor_component";
807
815
 
808
816
  // src/components/edit-component/component-modal.tsx
809
817
  import * as React8 from "react";
@@ -1000,7 +1008,6 @@ function EditComponent() {
1000
1008
  return /* @__PURE__ */ React9.createElement(ComponentModal, { element: elementDom, onClose: onBack });
1001
1009
  }
1002
1010
  function useHandleDocumentSwitches(path, setPath) {
1003
- const components = useSelector2(selectComponentsObject);
1004
1011
  const documentsManager = getV1DocumentsManager();
1005
1012
  useEffect4(
1006
1013
  () => listenTo(commandEndEvent2("editor/documents/attach-preview"), () => {
@@ -1013,14 +1020,14 @@ function useHandleDocumentSwitches(path, setPath) {
1013
1020
  if (currentComponentId) {
1014
1021
  apiClient.unlockComponent(currentComponentId);
1015
1022
  }
1016
- const isComponent = !!components?.[nextDocument.id];
1023
+ const isComponent = nextDocument.config.type === COMPONENT_DOCUMENT_TYPE;
1017
1024
  if (!isComponent) {
1018
1025
  setPath([]);
1019
1026
  return;
1020
1027
  }
1021
1028
  setPath(getUpdatedComponentPath(path, nextDocument));
1022
1029
  }),
1023
- [path, setPath, components, documentsManager]
1030
+ [path, setPath, documentsManager]
1024
1031
  );
1025
1032
  }
1026
1033
  function getUpdatedComponentPath(path, nextDocument) {
@@ -1239,14 +1246,15 @@ async function createComponentsBeforeSave({
1239
1246
  return;
1240
1247
  }
1241
1248
  try {
1242
- const tempIdToComponentId = await createComponents(unpublishedComponents, status);
1249
+ const uidToComponentId = await createComponents(unpublishedComponents, status);
1243
1250
  const elements = container.model.get("elements").toJSON();
1244
- updateComponentInstances(elements, tempIdToComponentId);
1251
+ updateComponentInstances(elements, uidToComponentId);
1245
1252
  dispatch4(
1246
1253
  slice.actions.add(
1247
1254
  unpublishedComponents.map((component) => ({
1248
- id: tempIdToComponentId.get(component.id),
1249
- name: component.name
1255
+ id: uidToComponentId.get(component.uid),
1256
+ name: component.name,
1257
+ uid: component.uid
1250
1258
  }))
1251
1259
  )
1252
1260
  );
@@ -1259,33 +1267,33 @@ async function createComponents(components, status) {
1259
1267
  const response = await apiClient.create({
1260
1268
  status,
1261
1269
  items: components.map((component) => ({
1262
- temp_id: component.id,
1270
+ uid: component.uid,
1263
1271
  title: component.name,
1264
1272
  elements: component.elements
1265
1273
  }))
1266
1274
  });
1267
1275
  const map = /* @__PURE__ */ new Map();
1268
1276
  Object.entries(response).forEach(([key, value]) => {
1269
- map.set(Number(key), value);
1277
+ map.set(key, value);
1270
1278
  });
1271
1279
  return map;
1272
1280
  }
1273
- function updateComponentInstances(elements, tempIdToComponentId) {
1281
+ function updateComponentInstances(elements, uidToComponentId) {
1274
1282
  elements.forEach((element) => {
1275
- const { shouldUpdate, newComponentId } = shouldUpdateElement(element, tempIdToComponentId);
1283
+ const { shouldUpdate, newComponentId } = shouldUpdateElement(element, uidToComponentId);
1276
1284
  if (shouldUpdate) {
1277
1285
  updateElementComponentId(element.id, newComponentId);
1278
1286
  }
1279
1287
  if (element.elements) {
1280
- updateComponentInstances(element.elements, tempIdToComponentId);
1288
+ updateComponentInstances(element.elements, uidToComponentId);
1281
1289
  }
1282
1290
  });
1283
1291
  }
1284
- function shouldUpdateElement(element, tempIdToComponentId) {
1292
+ function shouldUpdateElement(element, uidToComponentId) {
1285
1293
  if (element.widgetType === "e-component") {
1286
1294
  const currentComponentId = element.settings?.component?.value;
1287
- if (currentComponentId && tempIdToComponentId.has(currentComponentId)) {
1288
- return { shouldUpdate: true, newComponentId: tempIdToComponentId.get(currentComponentId) };
1295
+ if (currentComponentId && uidToComponentId.has(currentComponentId)) {
1296
+ return { shouldUpdate: true, newComponentId: uidToComponentId.get(currentComponentId) };
1289
1297
  }
1290
1298
  }
1291
1299
  return { shouldUpdate: false, newComponentId: null };
@@ -1333,7 +1341,7 @@ var beforeSave = ({ container, status }) => {
1333
1341
  };
1334
1342
 
1335
1343
  // src/init.ts
1336
- var COMPONENT_DOCUMENT_TYPE = "elementor_component";
1344
+ var COMPONENT_DOCUMENT_TYPE2 = "elementor_component";
1337
1345
  function init() {
1338
1346
  stylesRepository.register(componentsStylesProvider);
1339
1347
  registerSlice(slice);
@@ -1343,7 +1351,7 @@ function init() {
1343
1351
  );
1344
1352
  registerDataHook("dependency", "editor/documents/close", (args) => {
1345
1353
  const document = getV1CurrentDocument();
1346
- if (document.config.type === COMPONENT_DOCUMENT_TYPE) {
1354
+ if (document.config.type === COMPONENT_DOCUMENT_TYPE2) {
1347
1355
  args.mode = "autosave";
1348
1356
  }
1349
1357
  return true;