@elementor/editor-controls 3.35.0-428 → 3.35.0-430

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
@@ -3086,12 +3086,13 @@ var UrlControl = createControl(
3086
3086
 
3087
3087
  // src/controls/link-control.tsx
3088
3088
  import * as React65 from "react";
3089
- import { useState as useState11 } from "react";
3089
+ import { useEffect as useEffect7, useMemo as useMemo8, useState as useState11 } from "react";
3090
3090
  import { getLinkInLinkRestriction } from "@elementor/editor-elements";
3091
3091
  import { linkPropTypeUtil } from "@elementor/editor-props";
3092
3092
  import { MinusIcon, PlusIcon as PlusIcon2 } from "@elementor/icons";
3093
3093
  import { useSessionStorage } from "@elementor/session";
3094
3094
  import { Collapse, Grid as Grid10, IconButton as IconButton6, Stack as Stack10 } from "@elementor/ui";
3095
+ import { debounce as debounce3 } from "@elementor/utils";
3095
3096
  import { __ as __23 } from "@wordpress/i18n";
3096
3097
 
3097
3098
  // src/components/restricted-link-infotip.tsx
@@ -3442,6 +3443,30 @@ var LinkControl = createControl((props) => {
3442
3443
  } = props || {};
3443
3444
  const [linkInLinkRestriction, setLinkInLinkRestriction] = useState11(getLinkInLinkRestriction(elementId));
3444
3445
  const shouldDisableAddingLink = !isActive && linkInLinkRestriction.shouldRestrict;
3446
+ const debouncedCheckRestriction = useMemo8(
3447
+ () => debounce3(() => {
3448
+ const newRestriction = getLinkInLinkRestriction(elementId);
3449
+ if (newRestriction.shouldRestrict && isActive) {
3450
+ setIsActive(false);
3451
+ }
3452
+ setLinkInLinkRestriction(newRestriction);
3453
+ }, 300),
3454
+ [elementId, isActive]
3455
+ );
3456
+ useEffect7(() => {
3457
+ debouncedCheckRestriction();
3458
+ const handleInlineLinkChanged = (event) => {
3459
+ const customEvent = event;
3460
+ if (customEvent.detail.elementId === elementId) {
3461
+ debouncedCheckRestriction();
3462
+ }
3463
+ };
3464
+ window.addEventListener("elementor:inline-link-changed", handleInlineLinkChanged);
3465
+ return () => {
3466
+ window.removeEventListener("elementor:inline-link-changed", handleInlineLinkChanged);
3467
+ debouncedCheckRestriction.cancel();
3468
+ };
3469
+ }, [elementId, debouncedCheckRestriction]);
3445
3470
  const onEnabledChange = () => {
3446
3471
  setLinkInLinkRestriction(getLinkInLinkRestriction(elementId));
3447
3472
  if (linkInLinkRestriction.shouldRestrict && !isActive) {
@@ -3694,7 +3719,7 @@ var Control4 = ({
3694
3719
 
3695
3720
  // src/controls/aspect-ratio-control.tsx
3696
3721
  import * as React69 from "react";
3697
- import { useEffect as useEffect7, useState as useState13 } from "react";
3722
+ import { useEffect as useEffect8, useState as useState13 } from "react";
3698
3723
  import { stringPropTypeUtil as stringPropTypeUtil8 } from "@elementor/editor-props";
3699
3724
  import { MenuListItem as MenuListItem4 } from "@elementor/editor-ui";
3700
3725
  import { ArrowsMoveHorizontalIcon, ArrowsMoveVerticalIcon } from "@elementor/icons";
@@ -3721,7 +3746,7 @@ var AspectRatioControl = createControl(({ label }) => {
3721
3746
  const [selectedValue, setSelectedValue] = useState13(
3722
3747
  isCustomSelected ? CUSTOM_RATIO : aspectRatioValue || ""
3723
3748
  );
3724
- useEffect7(() => {
3749
+ useEffect8(() => {
3725
3750
  const isCustomValue = aspectRatioValue && !RATIO_OPTIONS.some((option) => option.value === aspectRatioValue);
3726
3751
  if (isCustomValue) {
3727
3752
  const [width, height] = aspectRatioValue.split("/");
@@ -4543,7 +4568,7 @@ var BackgroundClipField = () => {
4543
4568
 
4544
4569
  // src/controls/repeatable-control.tsx
4545
4570
  import * as React79 from "react";
4546
- import { useMemo as useMemo8 } from "react";
4571
+ import { useMemo as useMemo9 } from "react";
4547
4572
  import { createArrayPropUtils } from "@elementor/editor-props";
4548
4573
  import { Box as Box14 } from "@elementor/ui";
4549
4574
  var PLACEHOLDER_REGEX = /\$\{([^}]+)\}/g;
@@ -4563,11 +4588,11 @@ var RepeatableControl = createControl(
4563
4588
  if (!childPropTypeUtil) {
4564
4589
  return null;
4565
4590
  }
4566
- const childArrayPropTypeUtil2 = useMemo8(
4591
+ const childArrayPropTypeUtil2 = useMemo9(
4567
4592
  () => createArrayPropUtils(childPropTypeUtil.key, childPropTypeUtil.schema, propKey),
4568
4593
  [childPropTypeUtil.key, childPropTypeUtil.schema, propKey]
4569
4594
  );
4570
- const contextValue = useMemo8(
4595
+ const contextValue = useMemo9(
4571
4596
  () => ({
4572
4597
  ...childControlConfig,
4573
4598
  placeholder: placeholder || "",
@@ -4698,7 +4723,7 @@ var getAllProperties = (pattern) => {
4698
4723
 
4699
4724
  // src/controls/key-value-control.tsx
4700
4725
  import * as React80 from "react";
4701
- import { useMemo as useMemo9, useState as useState16 } from "react";
4726
+ import { useMemo as useMemo10, useState as useState16 } from "react";
4702
4727
  import {
4703
4728
  isTransformable,
4704
4729
  keyValuePropTypeUtil,
@@ -4741,7 +4766,7 @@ var KeyValueControl = createControl((props = {}) => {
4741
4766
  keyHelper: void 0,
4742
4767
  valueHelper: void 0
4743
4768
  };
4744
- const [keyRegex, valueRegex, errMsg] = useMemo9(
4769
+ const [keyRegex, valueRegex, errMsg] = useMemo10(
4745
4770
  () => [
4746
4771
  props.regexKey ? new RegExp(props.regexKey) : void 0,
4747
4772
  props.regexValue ? new RegExp(props.regexValue) : void 0,
@@ -5465,7 +5490,7 @@ var TransformBasePopoverTrigger = ({
5465
5490
 
5466
5491
  // src/controls/transition-control/transition-repeater-control.tsx
5467
5492
  import * as React97 from "react";
5468
- import { useEffect as useEffect8, useMemo as useMemo11, useState as useState17 } from "react";
5493
+ import { useEffect as useEffect9, useMemo as useMemo12, useState as useState17 } from "react";
5469
5494
  import {
5470
5495
  createArrayPropUtils as createArrayPropUtils2,
5471
5496
  selectionSizePropTypeUtil as selectionSizePropTypeUtil2
@@ -5476,7 +5501,7 @@ import { __ as __49 } from "@wordpress/i18n";
5476
5501
 
5477
5502
  // src/controls/selection-size-control.tsx
5478
5503
  import * as React95 from "react";
5479
- import { useMemo as useMemo10, useRef as useRef22 } from "react";
5504
+ import { useMemo as useMemo11, useRef as useRef22 } from "react";
5480
5505
  import { selectionSizePropTypeUtil } from "@elementor/editor-props";
5481
5506
  import { Grid as Grid28 } from "@elementor/ui";
5482
5507
  var SelectionSizeControl = createControl(
@@ -5484,7 +5509,7 @@ var SelectionSizeControl = createControl(
5484
5509
  const { value, setValue, propType } = useBoundProp(selectionSizePropTypeUtil);
5485
5510
  const rowRef = useRef22(null);
5486
5511
  const sizeFieldId = sizeLabel.replace(/\s+/g, "-").toLowerCase();
5487
- const currentSizeConfig = useMemo10(() => {
5512
+ const currentSizeConfig = useMemo11(() => {
5488
5513
  switch (value.selection.$$type) {
5489
5514
  case "key-value":
5490
5515
  return sizeConfigMap[value?.selection?.value.value.value || ""];
@@ -5793,15 +5818,15 @@ var TransitionRepeaterControl = createControl(
5793
5818
  const currentStyleIsNormal = currentStyleState === null;
5794
5819
  const [recentlyUsedList, setRecentlyUsedList] = useState17([]);
5795
5820
  const { value, setValue } = useBoundProp(childArrayPropTypeUtil);
5796
- const disabledItems = useMemo11(() => getDisabledItemLabels(value), [value]);
5797
- const allowedTransitionSet = useMemo11(() => {
5821
+ const disabledItems = useMemo12(() => getDisabledItemLabels(value), [value]);
5822
+ const allowedTransitionSet = useMemo12(() => {
5798
5823
  const set = /* @__PURE__ */ new Set();
5799
5824
  transitionProperties.forEach((category) => {
5800
5825
  category.properties.forEach((prop) => set.add(prop.value));
5801
5826
  });
5802
5827
  return set;
5803
5828
  }, []);
5804
- useEffect8(() => {
5829
+ useEffect9(() => {
5805
5830
  if (!value || value.length === 0) {
5806
5831
  return;
5807
5832
  }
@@ -5813,10 +5838,10 @@ var TransitionRepeaterControl = createControl(
5813
5838
  setValue(sanitized);
5814
5839
  }
5815
5840
  }, [allowedTransitionSet]);
5816
- useEffect8(() => {
5841
+ useEffect9(() => {
5817
5842
  recentlyUsedListGetter().then(setRecentlyUsedList);
5818
5843
  }, [recentlyUsedListGetter]);
5819
- const allPropertiesUsed = useMemo11(() => areAllPropertiesUsed(value), [value]);
5844
+ const allPropertiesUsed = useMemo12(() => areAllPropertiesUsed(value), [value]);
5820
5845
  const isAddItemDisabled = !currentStyleIsNormal || allPropertiesUsed;
5821
5846
  return /* @__PURE__ */ React97.createElement(
5822
5847
  RepeatableControl,
@@ -5925,7 +5950,7 @@ import { Box as Box24 } from "@elementor/ui";
5925
5950
  import * as React101 from "react";
5926
5951
  import {
5927
5952
  forwardRef as forwardRef10,
5928
- useEffect as useEffect11,
5953
+ useEffect as useEffect12,
5929
5954
  useRef as useRef26,
5930
5955
  useState as useState19
5931
5956
  } from "react";
@@ -5956,7 +5981,8 @@ function isEmpty(value = "") {
5956
5981
 
5957
5982
  // src/components/inline-editor-toolbar.tsx
5958
5983
  import * as React100 from "react";
5959
- import { useMemo as useMemo12, useRef as useRef25, useState as useState18 } from "react";
5984
+ import { useMemo as useMemo13, useRef as useRef25, useState as useState18 } from "react";
5985
+ import { getElementSetting } from "@elementor/editor-elements";
5960
5986
  import {
5961
5987
  BoldIcon,
5962
5988
  ItalicIcon,
@@ -5981,7 +6007,7 @@ import { __ as __51 } from "@wordpress/i18n";
5981
6007
 
5982
6008
  // src/components/url-popover.tsx
5983
6009
  import * as React99 from "react";
5984
- import { useEffect as useEffect9, useRef as useRef24 } from "react";
6010
+ import { useEffect as useEffect10, useRef as useRef24 } from "react";
5985
6011
  import { ExternalLinkIcon } from "@elementor/icons";
5986
6012
  import { bindPopover as bindPopover7, Popover as Popover7, Stack as Stack16, TextField as TextField8, ToggleButton as ToggleButton2, Tooltip as Tooltip9 } from "@elementor/ui";
5987
6013
  import { __ as __50 } from "@wordpress/i18n";
@@ -5995,7 +6021,7 @@ var UrlPopover = ({
5995
6021
  onToggleNewTab
5996
6022
  }) => {
5997
6023
  const inputRef = useRef24(null);
5998
- useEffect9(() => {
6024
+ useEffect10(() => {
5999
6025
  if (popupState.isOpen) {
6000
6026
  requestAnimationFrame(() => inputRef.current?.focus());
6001
6027
  }
@@ -6044,6 +6070,7 @@ var UrlPopover = ({
6044
6070
  };
6045
6071
 
6046
6072
  // src/components/inline-editor-toolbar.tsx
6073
+ var checkIfElementHasLink = (elementId) => !!getElementSetting(elementId, "link")?.value?.destination;
6047
6074
  var toolbarButtons = {
6048
6075
  clear: {
6049
6076
  label: __51("Clear", "elementor"),
@@ -6110,16 +6137,23 @@ var toolbarButtons = {
6110
6137
  };
6111
6138
  var { clear: clearButton, ...formatButtons } = toolbarButtons;
6112
6139
  var possibleFormats = Object.keys(formatButtons);
6113
- var InlineEditorToolbar = ({ editor }) => {
6140
+ var InlineEditorToolbar = ({ editor, elementId }) => {
6114
6141
  const [urlValue, setUrlValue] = useState18("");
6115
6142
  const [openInNewTab, setOpenInNewTab] = useState18(false);
6116
6143
  const toolbarRef = useRef25(null);
6117
6144
  const linkPopupState = usePopupState8({ variant: "popover" });
6145
+ const hasLinkOnElement = elementId ? checkIfElementHasLink(elementId) : false;
6118
6146
  const editorState = useEditorState({
6119
6147
  editor,
6120
6148
  selector: (ctx) => possibleFormats.filter((format) => ctx.editor.isActive(format))
6121
6149
  });
6122
- const formatButtonsList = useMemo12(() => Object.values(formatButtons), []);
6150
+ const formatButtonsList = useMemo13(() => {
6151
+ const buttons = Object.values(formatButtons);
6152
+ if (hasLinkOnElement) {
6153
+ return buttons.filter((button) => button.action !== "link");
6154
+ }
6155
+ return buttons;
6156
+ }, [hasLinkOnElement]);
6123
6157
  const handleLinkClick = () => {
6124
6158
  const linkAttrs = editor.getAttributes("link");
6125
6159
  setUrlValue(linkAttrs.href || "");
@@ -6141,6 +6175,13 @@ var InlineEditorToolbar = ({ editor }) => {
6141
6175
  } else {
6142
6176
  editor.chain().focus().unsetLink().run();
6143
6177
  }
6178
+ if (elementId) {
6179
+ window.dispatchEvent(
6180
+ new CustomEvent("elementor:inline-link-changed", {
6181
+ detail: { elementId }
6182
+ })
6183
+ );
6184
+ }
6144
6185
  linkPopupState.close();
6145
6186
  };
6146
6187
  React100.useEffect(() => {
@@ -6225,7 +6266,7 @@ var UNDERLINE_KEYBOARD_SHORTCUT = "u";
6225
6266
  var INITIAL_STYLE = "margin:0;padding:0;";
6226
6267
  var useOnUpdate = (callback, dependencies) => {
6227
6268
  const hasMounted = useRef26(false);
6228
- useEffect11(() => {
6269
+ useEffect12(() => {
6229
6270
  if (hasMounted.current) {
6230
6271
  callback();
6231
6272
  } else {
@@ -6270,7 +6311,8 @@ var InlineEditor = forwardRef10(
6270
6311
  sx = {},
6271
6312
  onBlur = void 0,
6272
6313
  getInitialPopoverPosition = void 0,
6273
- expectedTag = null
6314
+ expectedTag = null,
6315
+ elementId = void 0
6274
6316
  }, ref) => {
6275
6317
  const containerRef = useRef26(null);
6276
6318
  const popupState = usePopupState9({ variant: "popover", disableAutoFocus: true });
@@ -6404,7 +6446,7 @@ var InlineEditor = forwardRef10(
6404
6446
  anchorOrigin: { vertical: "top", horizontal: "center" },
6405
6447
  transformOrigin: { vertical: "bottom", horizontal: "center" }
6406
6448
  },
6407
- /* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor })
6449
+ /* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor, elementId })
6408
6450
  ));
6409
6451
  }
6410
6452
  );
@@ -6469,7 +6511,7 @@ var ClearIconButton = ({ tooltipText, onClick, disabled, size = "tiny" }) => /*
6469
6511
 
6470
6512
  // src/components/repeater/repeater.tsx
6471
6513
  import * as React104 from "react";
6472
- import { useEffect as useEffect12, useState as useState20 } from "react";
6514
+ import { useEffect as useEffect13, useState as useState20 } from "react";
6473
6515
  import { CopyIcon as CopyIcon2, EyeIcon as EyeIcon2, EyeOffIcon as EyeOffIcon2, PlusIcon as PlusIcon3, XIcon as XIcon4 } from "@elementor/icons";
6474
6516
  import {
6475
6517
  bindPopover as bindPopover9,
@@ -6657,7 +6699,7 @@ var usePopover = (openOnMount, onOpen) => {
6657
6699
  const [ref, setRef] = useState20(null);
6658
6700
  const popoverState = usePopupState10({ variant: "popover" });
6659
6701
  const popoverProps = bindPopover9(popoverState);
6660
- useEffect12(() => {
6702
+ useEffect13(() => {
6661
6703
  if (openOnMount && ref) {
6662
6704
  popoverState.open(ref);
6663
6705
  onOpen?.();