@elementor/editor-controls 3.32.0-40 → 3.32.0-42

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 CHANGED
@@ -1117,7 +1117,7 @@ var import_i18n4 = require("@wordpress/i18n");
1117
1117
  // src/components/section-content.tsx
1118
1118
  var React18 = __toESM(require("react"));
1119
1119
  var import_ui13 = require("@elementor/ui");
1120
- var SectionContent = ({ gap = 2, sx, children }) => /* @__PURE__ */ React18.createElement(import_ui13.Stack, { gap, sx: { ...sx } }, children);
1120
+ var SectionContent = ({ gap = 0.5, sx, children }) => /* @__PURE__ */ React18.createElement(import_ui13.Stack, { gap, sx: { ...sx } }, children);
1121
1121
 
1122
1122
  // src/controls/color-control.tsx
1123
1123
  var React19 = __toESM(require("react"));
@@ -1329,12 +1329,12 @@ var Repeater = ({
1329
1329
  persistWhen: () => true
1330
1330
  });
1331
1331
  const [uniqueKeys, setUniqueKeys] = (0, import_react16.useState)(items2.map((_, index) => index));
1332
- const generateNextKey2 = (source) => {
1332
+ const generateNextKey = (source) => {
1333
1333
  return 1 + Math.max(0, ...source);
1334
1334
  };
1335
1335
  const addRepeaterItem = () => {
1336
1336
  const newItem = structuredClone(itemSettings.initialValues);
1337
- const newKey = generateNextKey2(uniqueKeys);
1337
+ const newKey = generateNextKey(uniqueKeys);
1338
1338
  if (addToBottom) {
1339
1339
  setItems([...items2, newItem]);
1340
1340
  setUniqueKeys([...uniqueKeys, newKey]);
@@ -1348,7 +1348,7 @@ var Repeater = ({
1348
1348
  };
1349
1349
  const duplicateRepeaterItem = (index) => {
1350
1350
  const newItem = structuredClone(items2[index]);
1351
- const newKey = generateNextKey2(uniqueKeys);
1351
+ const newKey = generateNextKey(uniqueKeys);
1352
1352
  const atPosition = 1 + index;
1353
1353
  setItems([...items2.slice(0, atPosition), newItem, ...items2.slice(atPosition)]);
1354
1354
  setUniqueKeys([...uniqueKeys.slice(0, atPosition), newKey, ...uniqueKeys.slice(atPosition)]);
@@ -3370,13 +3370,20 @@ var RepeaterContextProvider = ({
3370
3370
  setExternal: setRepeaterValues,
3371
3371
  persistWhen: () => true
3372
3372
  });
3373
- const itemWithKeysState = (0, import_react30.useState)(
3374
- items2?.map((item, index) => ({ key: index, item })) ?? []
3375
- );
3376
- const itemsWithKeys = itemWithKeysState[0];
3377
- const setItemsWithKeys = (newItems) => {
3378
- itemWithKeysState[1](newItems);
3379
- setItems(newItems.map(({ item }) => item));
3373
+ const [itemsWithKeys, setItemsWithKeys] = (0, import_react30.useState)(() => {
3374
+ return items2?.map((item) => ({ key: generateUniqueKey(), item })) ?? [];
3375
+ });
3376
+ React49.useEffect(() => {
3377
+ setItemsWithKeys((prevItemsWithKeys) => {
3378
+ const newItemsWithKeys = items2?.map((item) => {
3379
+ const existingItem = prevItemsWithKeys.find((i) => i.item === item);
3380
+ return existingItem || { key: generateUniqueKey(), item };
3381
+ }) ?? [];
3382
+ return newItemsWithKeys;
3383
+ });
3384
+ }, [items2]);
3385
+ const handleSetItems = (newItemsWithKeys) => {
3386
+ setItems(newItemsWithKeys.map(({ item }) => item));
3380
3387
  };
3381
3388
  const [openItemIndex, setOpenItemIndex] = (0, import_react30.useState)(EMPTY_OPEN_ITEM2);
3382
3389
  const [rowRef, setRowRef] = (0, import_react30.useState)(null);
@@ -3385,19 +3392,18 @@ var RepeaterContextProvider = ({
3385
3392
  const addItem = (ev, config) => {
3386
3393
  const item = config?.item ?? initial;
3387
3394
  const newIndex = config?.index ?? items2.length;
3388
- const newKey = generateNextKey(itemsWithKeys.map(({ key }) => key));
3389
- const newItemsWithKeys = [...itemsWithKeys];
3390
- newItemsWithKeys.splice(newIndex, 0, { item, key: newKey });
3391
- setItemsWithKeys(newItemsWithKeys);
3395
+ const newItems = [...items2];
3396
+ newItems.splice(newIndex, 0, item);
3397
+ setItems(newItems);
3392
3398
  setOpenItemIndex(newIndex);
3393
3399
  popoverState.open(rowRef ?? ev);
3394
3400
  };
3395
3401
  const removeItem = (index) => {
3396
- setItemsWithKeys(itemsWithKeys.filter((_, pos) => pos !== index));
3402
+ setItems(items2.filter((_, pos) => pos !== index));
3397
3403
  };
3398
3404
  const updateItem = (updatedItem, index) => {
3399
- const item = itemsWithKeys[index];
3400
- setItemsWithKeys(itemsWithKeys.toSpliced(index, 1, { ...item, item: updatedItem }));
3405
+ const newItems = [...items2.slice(0, index), updatedItem, ...items2.slice(index + 1)];
3406
+ setItems(newItems);
3401
3407
  };
3402
3408
  return /* @__PURE__ */ React49.createElement(
3403
3409
  RepeaterContext.Provider,
@@ -3407,7 +3413,7 @@ var RepeaterContextProvider = ({
3407
3413
  openItemIndex,
3408
3414
  setOpenItemIndex,
3409
3415
  items: itemsWithKeys ?? [],
3410
- setItems: setItemsWithKeys,
3416
+ setItems: handleSetItems,
3411
3417
  popoverState,
3412
3418
  initial,
3413
3419
  updateItem,
@@ -3420,8 +3426,8 @@ var RepeaterContextProvider = ({
3420
3426
  children
3421
3427
  );
3422
3428
  };
3423
- var generateNextKey = (source) => {
3424
- return 1 + Math.max(0, ...source);
3429
+ var generateUniqueKey = () => {
3430
+ return Date.now() + Math.floor(Math.random() * 1e6);
3425
3431
  };
3426
3432
 
3427
3433
  // src/components/unstable-repeater/actions/tooltip-add-item-action.tsx
@@ -3434,7 +3440,7 @@ var TooltipAddItemAction = ({
3434
3440
  }) => {
3435
3441
  const { addItem } = useRepeaterContext();
3436
3442
  const onClick = (ev) => addItem(ev, { index: newItemIndex });
3437
- return /* @__PURE__ */ React50.createElement(ConditionalToolTip, { content: tooltipContent, enable: enableTooltip }, /* @__PURE__ */ React50.createElement(import_ui42.Box, null, /* @__PURE__ */ React50.createElement(
3443
+ return /* @__PURE__ */ React50.createElement(ConditionalToolTip, { content: tooltipContent, enable: enableTooltip }, /* @__PURE__ */ React50.createElement(import_ui42.Box, { sx: { ml: "auto" } }, /* @__PURE__ */ React50.createElement(
3438
3444
  import_ui42.IconButton,
3439
3445
  {
3440
3446
  size: SIZE4,
@@ -3602,7 +3608,20 @@ var TransformBaseControl = ({ anchorRef }) => {
3602
3608
  // src/components/unstable-repeater/header/header.tsx
3603
3609
  var Header = ({ label, children }) => {
3604
3610
  const { value } = useBoundProp();
3605
- return /* @__PURE__ */ React54.createElement(import_ui46.Stack, { direction: "row", justifyContent: "start", alignItems: "center", gap: 1, sx: { marginInlineEnd: -0.75 } }, /* @__PURE__ */ React54.createElement(import_ui46.Typography, { component: "label", variant: "caption", color: "text.secondary" }, label), /* @__PURE__ */ React54.createElement(RepeaterHeaderActionsSlot, { value }), /* @__PURE__ */ React54.createElement(SlotChildren, { whitelist: [TransformBaseControl, TooltipAddItemAction], sorted: true }, children), /* @__PURE__ */ React54.createElement(ControlAdornments, null));
3611
+ return /* @__PURE__ */ React54.createElement(
3612
+ import_ui46.Stack,
3613
+ {
3614
+ direction: "row",
3615
+ justifyContent: "start",
3616
+ alignItems: "center",
3617
+ gap: 1,
3618
+ sx: { marginInlineEnd: -0.75, py: 0.25 }
3619
+ },
3620
+ /* @__PURE__ */ React54.createElement(import_ui46.Typography, { component: "label", variant: "caption", color: "text.secondary", sx: { lineHeight: 1 } }, label),
3621
+ /* @__PURE__ */ React54.createElement(RepeaterHeaderActionsSlot, { value }),
3622
+ /* @__PURE__ */ React54.createElement(SlotChildren, { whitelist: [TransformBaseControl, TooltipAddItemAction], sorted: true }, children),
3623
+ /* @__PURE__ */ React54.createElement(ControlAdornments, null)
3624
+ );
3606
3625
  };
3607
3626
 
3608
3627
  // src/components/unstable-repeater/items/items-container.tsx
@@ -4200,8 +4219,8 @@ var ItemIconImage = ({ value }) => {
4200
4219
  {
4201
4220
  image: imageUrl,
4202
4221
  sx: (theme) => ({
4203
- height: "1em",
4204
- width: "1em",
4222
+ height: "1rem",
4223
+ width: "1rem",
4205
4224
  borderRadius: `${theme.shape.borderRadius / 2}px`,
4206
4225
  outline: `1px solid ${theme.palette.action.disabled}`
4207
4226
  })