-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add elementor integration #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
4c2fca8
5a86027
15aac82
527c3a6
11367f4
cf97ffb
ed9014d
ecc4b53
79ebfcb
21d65a8
0441e27
084bebe
a84b1b0
e30c49b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,11 @@ | ||||||||||||||||||||||||||||||||||
| import TargetSVG from '~interact/editor/assets/target.svg' | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import { GridLayout, FlexLayout } from '~interact/editor/components' | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| getSelectedBlockAnchor, | ||||||||||||||||||||||||||||||||||
| isElementorEditor, | ||||||||||||||||||||||||||||||||||
| startElementorElementPicker, | ||||||||||||||||||||||||||||||||||
| } from '~interact/editor/editors' | ||||||||||||||||||||||||||||||||||
| import { getOrGenerateBlockAnchor, getOrGenerateBlockClass } from '~interact/editor/util' | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| SelectControl, | ||||||||||||||||||||||||||||||||||
|
|
@@ -40,6 +45,9 @@ const TargetSelector = props => { | |||||||||||||||||||||||||||||||||
| const [ isPopoverOpen, setIsPopoverOpen ] = useState( false ) | ||||||||||||||||||||||||||||||||||
| const [ buttonRef, setButtonRef ] = useState( null ) | ||||||||||||||||||||||||||||||||||
| const prevValueRef = useRef( {} ) | ||||||||||||||||||||||||||||||||||
| const elementPickerStopRef = useRef( null ) | ||||||||||||||||||||||||||||||||||
| const isElementor = isElementorEditor() | ||||||||||||||||||||||||||||||||||
| const hasBlockEditor = !! select( 'core/block-editor' )?.getSelectedBlockClientId | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const targetButton = ( | ||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||
|
|
@@ -50,14 +58,24 @@ const TargetSelector = props => { | |||||||||||||||||||||||||||||||||
| ref={ setButtonRef } | ||||||||||||||||||||||||||||||||||
| onClick={ () => { | ||||||||||||||||||||||||||||||||||
| onBlockSelectClick() | ||||||||||||||||||||||||||||||||||
| if ( hasPickerPopover && ! isPopoverOpen ) { | ||||||||||||||||||||||||||||||||||
| if ( isElementor ) { | ||||||||||||||||||||||||||||||||||
| elementPickerStopRef.current?.() | ||||||||||||||||||||||||||||||||||
| elementPickerStopRef.current = startElementorElementPicker( { | ||||||||||||||||||||||||||||||||||
| targetType: value.type === 'class' ? 'class' : 'selector', | ||||||||||||||||||||||||||||||||||
| onPick: target => { | ||||||||||||||||||||||||||||||||||
| onChange( target ) | ||||||||||||||||||||||||||||||||||
| onBlockSelectDone() | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| onCancel: onBlockSelectDone, | ||||||||||||||||||||||||||||||||||
| } ) | ||||||||||||||||||||||||||||||||||
| } else if ( hasPickerPopover && ! isPopoverOpen ) { | ||||||||||||||||||||||||||||||||||
| setIsPopoverOpen( true ) | ||||||||||||||||||||||||||||||||||
| } else if ( hasPickerPopover && isPopoverOpen ) { | ||||||||||||||||||||||||||||||||||
| setIsPopoverOpen( false ) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } } | ||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||
| { hasPickerPopover && isPopoverOpen && ( | ||||||||||||||||||||||||||||||||||
| { hasPickerPopover && isPopoverOpen && ! isElementor && ( | ||||||||||||||||||||||||||||||||||
| <BlockPickerPopover | ||||||||||||||||||||||||||||||||||
| anchor={ anchor || buttonRef } | ||||||||||||||||||||||||||||||||||
| placement="left" | ||||||||||||||||||||||||||||||||||
|
|
@@ -148,6 +166,18 @@ const TargetSelector = props => { | |||||||||||||||||||||||||||||||||
| targetOptions = targetOptions.filter( target => target.value !== 'trigger' ) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ( isElementor ) { | ||||||||||||||||||||||||||||||||||
| targetOptions = targetOptions.filter( target => | ||||||||||||||||||||||||||||||||||
| [ 'trigger', 'class', 'selector' ].includes( target.value ) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+169
to
+173
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saved When Elementor is active, A 🐛 Proposed fix if ( isElementor ) {
targetOptions = targetOptions.filter( target =>
[ 'trigger', 'class', 'selector' ].includes( target.value )
)
}
+useEffect( () => {
+ if ( isElementor && ! [ 'trigger', 'class', 'selector' ].includes( value.type ) ) {
+ onChange( { ...value, type: 'selector', value: '' } )
+ }
+}, [ isElementor ] ) // eslint-disable-line react-hooks/exhaustive-deps📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| useEffect( () => { | ||||||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||||||
| elementPickerStopRef.current?.() | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }, [] ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Watch for warnings, we need to throttle this because we are subscribed to | ||||||||||||||||||||||||||||||||||
| // the editor and changes can be fast. | ||||||||||||||||||||||||||||||||||
| const [ targetWarning, setTargetWarning ] = useState( getTargetSelectorWarning( value.type, value.value ) ) | ||||||||||||||||||||||||||||||||||
|
|
@@ -176,7 +206,7 @@ const TargetSelector = props => { | |||||||||||||||||||||||||||||||||
| const newTarget = { ...value, type } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Use any previous values we may have already entered. | ||||||||||||||||||||||||||||||||||
| if ( type === 'block-name' ) { | ||||||||||||||||||||||||||||||||||
| if ( type === 'block-name' && hasBlockEditor ) { | ||||||||||||||||||||||||||||||||||
| if ( prevValueRef.current[ type ] ) { | ||||||||||||||||||||||||||||||||||
| newTarget.value = prevValueRef.current[ type ] | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
|
|
@@ -207,7 +237,7 @@ const TargetSelector = props => { | |||||||||||||||||||||||||||||||||
| className="interact-target-block-input" | ||||||||||||||||||||||||||||||||||
| id="interact-target-block-input" | ||||||||||||||||||||||||||||||||||
| label={ __( 'Block Anchor / ID', 'interactions' ) } | ||||||||||||||||||||||||||||||||||
| value={ value.value } | ||||||||||||||||||||||||||||||||||
| value={ value.value || ( isElementor ? '' : getSelectedBlockAnchor() || '' ) } | ||||||||||||||||||||||||||||||||||
| // When typing, the previous blockName should be invalid | ||||||||||||||||||||||||||||||||||
| onChange={ targetValue => onChange( { | ||||||||||||||||||||||||||||||||||
| ...value, blockName: '', value: targetValue, | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.