Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] [Embed block] Detect when an embeddable URL is pasted into…
… an empty paragraph (#35204) * added unstableEmbedURLOnPaste prop to activate embed detection. * reintegrated Embed transformation that was disabled - testing required. * Added functionality that would convert the URL to a link. * integrated the bottom sheet component that displays Create embed/link. * The EmbedHandlerPicker was extracted to a standalone component. * Updated changelog. * added onChange to the embed logic so that the url is visible. * only process URLs on empty paragraphs. * utilized useCallback to lessen re-renders. * added pickerOptions to the dependencies array. * if there is content within a paragraph then insert the link. * utilized isEmpty to check the text property of value. * memoized the EmbedHandlerPicker * Added a comment to clarify changes. * Fixed issue with release notes that doesn't follow format. * refactored embed paste logic. * disables onReplace on non embed rich-text instances. * Fixed CHANGELOG formatting issue. * Fixed formatting issue in CHANGELOG. * refactored the Embed pasting logic so that it is centralized * Changed the variable to something more meaningful. * Removed unnecessary content length check since this is already checked. * if block is not derived then we check if content is a string url. * Refactor embed paste logic * Removed the __unstableEmbedURLOnPaste flag from mode logic for Heading * Resolved isPastedURL logic issues to fix HEADING bug. * Fixed typo in CHANGELOG. Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
- Loading branch information
1 parent
ae12d94
commit 5430baf
Showing
6 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/block-editor/src/components/rich-text/embed-handler-picker.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
forwardRef, | ||
useRef, | ||
useImperativeHandle, | ||
memo, | ||
useCallback, | ||
} from '@wordpress/element'; | ||
import { Picker } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const DEFAULT_PICKER_OPTIONS = [ | ||
{ | ||
id: 'createEmbed', | ||
label: __( 'Create embed' ), | ||
value: 'createEmbed', | ||
onSelect: noop, | ||
}, | ||
{ | ||
id: 'createLink', | ||
label: __( 'Create link' ), | ||
value: 'createLink', | ||
onSelect: noop, | ||
}, | ||
]; | ||
|
||
const EmbedHandlerPicker = forwardRef( ( {}, ref ) => { | ||
const pickerRef = useRef(); | ||
const pickerOptions = useRef( DEFAULT_PICKER_OPTIONS ).current; | ||
|
||
const onPickerSelect = useCallback( | ||
( value ) => { | ||
const selectedItem = pickerOptions.find( | ||
( item ) => item.value === value | ||
); | ||
selectedItem.onSelect(); | ||
}, | ||
[ pickerOptions ] | ||
); | ||
|
||
useImperativeHandle( ref, () => ( { | ||
presentPicker: ( { createEmbed, createLink } ) => { | ||
pickerOptions[ 0 ].onSelect = createEmbed; | ||
pickerOptions[ 1 ].onSelect = createLink; | ||
pickerRef.current?.presentPicker(); | ||
}, | ||
} ) ); | ||
|
||
return ( | ||
<Picker | ||
ref={ pickerRef } | ||
options={ pickerOptions } | ||
onChange={ onPickerSelect } | ||
hideCancelButton | ||
leftAlign | ||
/> | ||
); | ||
} ); | ||
|
||
export default memo( EmbedHandlerPicker ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters