@elementor/editor-controls 4.4.0-1096 → 4.4.0-1097

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
@@ -4713,33 +4713,39 @@ var LinkControl = createControl((props) => {
4713
4713
  (0, import_editor_elements2.getLinkInLinkRestriction)(elementId, value ?? linkPlaceholder)
4714
4714
  );
4715
4715
  const shouldDisableAddingLink = !isActive && linkInLinkRestriction.shouldRestrict;
4716
- const debouncedCheckRestriction = (0, import_utils5.useDebouncedCallback)(() => {
4716
+ const syncLinkRestriction = (clearActiveLinkWhen = "restricted") => {
4717
4717
  const newRestriction = (0, import_editor_elements2.getLinkInLinkRestriction)(elementId, value ?? linkPlaceholder);
4718
- if (newRestriction.shouldRestrict && isActive && !linkPlaceholder) {
4718
+ const becameRestricted = newRestriction.shouldRestrict && !linkInLinkRestriction.shouldRestrict;
4719
+ const shouldClearActiveLink = clearActiveLinkWhen === "newly-restricted" ? becameRestricted : newRestriction.shouldRestrict;
4720
+ if (shouldClearActiveLink && isActive && !linkPlaceholder) {
4719
4721
  setIsActive(false);
4720
4722
  if (value !== null) {
4721
4723
  setValue(null);
4722
4724
  }
4723
4725
  }
4724
4726
  setLinkInLinkRestriction((prev) => isSameRestriction(prev, newRestriction) ? prev : newRestriction);
4725
- }, 300);
4727
+ };
4728
+ const debouncedSyncLinkRestriction = (0, import_utils5.useDebouncedCallback)(
4729
+ (clearActiveLinkWhen = "restricted") => syncLinkRestriction(clearActiveLinkWhen),
4730
+ 300
4731
+ );
4726
4732
  (0, import_editor_v1_adapters.__privateUseListenTo)(
4727
4733
  (0, import_editor_v1_adapters.commandEndEvent)("document/elements/set-settings"),
4728
4734
  () => {
4729
- debouncedCheckRestriction();
4735
+ debouncedSyncLinkRestriction("newly-restricted");
4730
4736
  },
4731
- [debouncedCheckRestriction]
4737
+ [debouncedSyncLinkRestriction]
4732
4738
  );
4733
4739
  (0, import_react43.useEffect)(() => {
4734
- debouncedCheckRestriction();
4740
+ debouncedSyncLinkRestriction();
4735
4741
  const handleInlineLinkChanged = () => {
4736
- debouncedCheckRestriction();
4742
+ debouncedSyncLinkRestriction();
4737
4743
  };
4738
4744
  window.addEventListener("elementor:inline-link-changed", handleInlineLinkChanged);
4739
4745
  return () => {
4740
4746
  window.removeEventListener("elementor:inline-link-changed", handleInlineLinkChanged);
4741
4747
  };
4742
- }, [elementId, debouncedCheckRestriction]);
4748
+ }, [elementId, debouncedSyncLinkRestriction]);
4743
4749
  const onEnabledChange = () => {
4744
4750
  setLinkInLinkRestriction((0, import_editor_elements2.getLinkInLinkRestriction)(elementId, value ?? linkPlaceholder));
4745
4751
  if (linkInLinkRestriction.shouldRestrict && !isActive) {