@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-controls",
3
3
  "description": "This package contains the controls model and utils for the Elementor editor",
4
- "version": "3.35.0-428",
4
+ "version": "3.35.0-430",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,22 +40,22 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "3.35.0-428",
44
- "@elementor/editor-elements": "3.35.0-428",
45
- "@elementor/editor-props": "3.35.0-428",
46
- "@elementor/editor-responsive": "3.35.0-428",
47
- "@elementor/editor-ui": "3.35.0-428",
48
- "@elementor/editor-v1-adapters": "3.35.0-428",
49
- "@elementor/env": "3.35.0-428",
50
- "@elementor/http-client": "3.35.0-428",
43
+ "@elementor/editor-current-user": "3.35.0-430",
44
+ "@elementor/editor-elements": "3.35.0-430",
45
+ "@elementor/editor-props": "3.35.0-430",
46
+ "@elementor/editor-responsive": "3.35.0-430",
47
+ "@elementor/editor-ui": "3.35.0-430",
48
+ "@elementor/editor-v1-adapters": "3.35.0-430",
49
+ "@elementor/env": "3.35.0-430",
50
+ "@elementor/http-client": "3.35.0-430",
51
51
  "@elementor/icons": "^1.63.0",
52
- "@elementor/locations": "3.35.0-428",
53
- "@elementor/mixpanel": "3.35.0-428",
54
- "@elementor/query": "3.35.0-428",
55
- "@elementor/session": "3.35.0-428",
52
+ "@elementor/locations": "3.35.0-430",
53
+ "@elementor/mixpanel": "3.35.0-430",
54
+ "@elementor/query": "3.35.0-430",
55
+ "@elementor/session": "3.35.0-430",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "3.35.0-428",
58
- "@elementor/wp-media": "3.35.0-428",
57
+ "@elementor/utils": "3.35.0-430",
58
+ "@elementor/wp-media": "3.35.0-430",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useMemo, useRef, useState } from 'react';
3
+ import { type ElementID, getElementSetting } from '@elementor/editor-elements';
4
+ import { type LinkPropValue } from '@elementor/editor-props';
3
5
  import {
4
6
  BoldIcon,
5
7
  ItalicIcon,
@@ -24,8 +26,12 @@ import { __ } from '@wordpress/i18n';
24
26
 
25
27
  import { UrlPopover } from './url-popover';
26
28
 
29
+ const checkIfElementHasLink = ( elementId: ElementID ): boolean =>
30
+ !! getElementSetting< LinkPropValue >( elementId, 'link' )?.value?.destination;
31
+
27
32
  type InlineEditorToolbarProps = {
28
33
  editor: Editor;
34
+ elementId?: ElementID;
29
35
  };
30
36
 
31
37
  const toolbarButtons = {
@@ -101,18 +107,27 @@ const { clear: clearButton, ...formatButtons } = toolbarButtons;
101
107
 
102
108
  const possibleFormats: FormatAction[] = Object.keys( formatButtons ) as FormatAction[];
103
109
 
104
- export const InlineEditorToolbar = ( { editor }: InlineEditorToolbarProps ) => {
110
+ export const InlineEditorToolbar = ( { editor, elementId }: InlineEditorToolbarProps ) => {
105
111
  const [ urlValue, setUrlValue ] = useState( '' );
106
112
  const [ openInNewTab, setOpenInNewTab ] = useState( false );
107
113
  const toolbarRef = useRef< HTMLDivElement >( null );
108
114
  const linkPopupState = usePopupState( { variant: 'popover' } );
115
+ const hasLinkOnElement = elementId ? checkIfElementHasLink( elementId ) : false;
109
116
 
110
117
  const editorState = useEditorState( {
111
118
  editor,
112
119
  selector: ( ctx ) => possibleFormats.filter( ( format ) => ctx.editor.isActive( format ) ),
113
120
  } );
114
121
 
115
- const formatButtonsList = useMemo( () => Object.values( formatButtons ), [] );
122
+ const formatButtonsList = useMemo( () => {
123
+ const buttons = Object.values( formatButtons );
124
+
125
+ if ( hasLinkOnElement ) {
126
+ return buttons.filter( ( button ) => button.action !== 'link' );
127
+ }
128
+
129
+ return buttons;
130
+ }, [ hasLinkOnElement ] );
116
131
 
117
132
  const handleLinkClick = () => {
118
133
  const linkAttrs = editor.getAttributes( 'link' );
@@ -142,6 +157,15 @@ export const InlineEditorToolbar = ( { editor }: InlineEditorToolbarProps ) => {
142
157
  } else {
143
158
  editor.chain().focus().unsetLink().run();
144
159
  }
160
+
161
+ if ( elementId ) {
162
+ window.dispatchEvent(
163
+ new CustomEvent( 'elementor:inline-link-changed', {
164
+ detail: { elementId },
165
+ } )
166
+ );
167
+ }
168
+
145
169
  linkPopupState.close();
146
170
  };
147
171
 
@@ -31,6 +31,8 @@ const ITALIC_KEYBOARD_SHORTCUT = 'i';
31
31
  const BOLD_KEYBOARD_SHORTCUT = 'b';
32
32
  const UNDERLINE_KEYBOARD_SHORTCUT = 'u';
33
33
 
34
+ import type { ElementID } from '@elementor/editor-elements';
35
+
34
36
  type InlineEditorProps = {
35
37
  value: string | null;
36
38
  setValue: ( value: string | null ) => void;
@@ -42,6 +44,7 @@ type InlineEditorProps = {
42
44
  autofocus?: boolean;
43
45
  getInitialPopoverPosition?: () => { left: number; top: number };
44
46
  expectedTag?: string | null;
47
+ elementId?: ElementID;
45
48
  };
46
49
 
47
50
  const INITIAL_STYLE = 'margin:0;padding:0;';
@@ -124,6 +127,7 @@ export const InlineEditor = forwardRef(
124
127
  onBlur = undefined,
125
128
  getInitialPopoverPosition = undefined,
126
129
  expectedTag = null,
130
+ elementId = undefined,
127
131
  }: InlineEditorProps,
128
132
  ref
129
133
  ) => {
@@ -289,7 +293,7 @@ export const InlineEditor = forwardRef(
289
293
  anchorOrigin={ { vertical: 'top', horizontal: 'center' } }
290
294
  transformOrigin={ { vertical: 'bottom', horizontal: 'center' } }
291
295
  >
292
- <InlineEditorToolbar editor={ editor } />
296
+ <InlineEditorToolbar editor={ editor } elementId={ elementId } />
293
297
  </Popover>
294
298
  ) }
295
299
  </>
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
- import { useState } from 'react';
2
+ import { useEffect, useMemo, useState } from 'react';
3
3
  import { getLinkInLinkRestriction } from '@elementor/editor-elements';
4
4
  import { linkPropTypeUtil, type LinkPropValue } from '@elementor/editor-props';
5
5
  import { MinusIcon, PlusIcon } from '@elementor/icons';
6
6
  import { useSessionStorage } from '@elementor/session';
7
7
  import { Collapse, Grid, IconButton, Stack } from '@elementor/ui';
8
+ import { debounce } from '@elementor/utils';
8
9
  import { __ } from '@wordpress/i18n';
9
10
 
10
11
  import { PropKeyProvider, PropProvider, useBoundProp } from '../bound-prop-context';
@@ -57,6 +58,39 @@ export const LinkControl = createControl( ( props: Props ) => {
57
58
  const [ linkInLinkRestriction, setLinkInLinkRestriction ] = useState( getLinkInLinkRestriction( elementId ) );
58
59
  const shouldDisableAddingLink = ! isActive && linkInLinkRestriction.shouldRestrict;
59
60
 
61
+ const debouncedCheckRestriction = useMemo(
62
+ () =>
63
+ debounce( () => {
64
+ const newRestriction = getLinkInLinkRestriction( elementId );
65
+
66
+ if ( newRestriction.shouldRestrict && isActive ) {
67
+ setIsActive( false );
68
+ }
69
+
70
+ setLinkInLinkRestriction( newRestriction );
71
+ }, 300 ),
72
+ [ elementId, isActive ]
73
+ );
74
+
75
+ useEffect( () => {
76
+ debouncedCheckRestriction();
77
+
78
+ const handleInlineLinkChanged = ( event: Event ) => {
79
+ const customEvent = event as CustomEvent< { elementId: string } >;
80
+
81
+ if ( customEvent.detail.elementId === elementId ) {
82
+ debouncedCheckRestriction();
83
+ }
84
+ };
85
+
86
+ window.addEventListener( 'elementor:inline-link-changed', handleInlineLinkChanged );
87
+
88
+ return () => {
89
+ window.removeEventListener( 'elementor:inline-link-changed', handleInlineLinkChanged );
90
+ debouncedCheckRestriction.cancel();
91
+ };
92
+ }, [ elementId, debouncedCheckRestriction ] );
93
+
60
94
  const onEnabledChange = () => {
61
95
  setLinkInLinkRestriction( getLinkInLinkRestriction( elementId ) );
62
96