Skip to content
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

RNMobile release v1.22.0 #20062

Merged
merged 120 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
d4b7692
Use Select: Fix render queue. (#19286)
epiqueras Jan 20, 2020
e654dce
Project Management: Run pull request automation on closed (#19742)
aduth Jan 20, 2020
5ba3976
Try/group block custom text color (#19181)
glendaviesnz Jan 20, 2020
80824d7
Block Editor: Handle LinkControl submission via form handler (#19651)
aduth Jan 20, 2020
1ffedef
Added conditions and new translation strings for BlockMover (#19757)
momotofu Jan 21, 2020
9788231
Storybook: Add Placeholder component story (#19734)
mkaz Jan 21, 2020
942c262
Project Management: Fix pull request merge automation errors (#19768)
aduth Jan 21, 2020
056dd36
Add post requests documentation for apiFetch (#19759)
momotofu Jan 21, 2020
f6c90ed
Multi-select: don't focus first selected block (#19762)
ellatrix Jan 21, 2020
d6487f3
Update: Readme.txt Link to changelog instead of adding it inline(#19761)
jorgefilipecosta Jan 21, 2020
aad7459
Fix: Media & Text: "Crop image to fill entire column" reset on image …
jorgefilipecosta Jan 21, 2020
cd309db
Build: Include JSON files in zip archive (#19772)
ockham Jan 21, 2020
24c0e60
Makes appenders visible only for the current selection (#19598)
draganescu Jan 21, 2020
26062c8
Core-data: do not publish outdated state to subscribers during update…
alshakero Jan 21, 2020
7d59200
Add WordPress primitives package (#19781)
youknowriad Jan 21, 2020
c22b77c
navigation-link: set page id in the attrs (#18641)
retrofox Jan 21, 2020
b39e9d9
Project management: Add step that updates CHANGELOG files before npm …
gziolo Jan 21, 2020
b77d71a
Navigation Block: Add submenu chevron w/ setting (#19601)
WunderBart Jan 21, 2020
567cdb9
Embed: Fix failure placeholder alignment/sizing (#19673)
Jan 21, 2020
76304dd
Fix card component sub-component example code (#19802)
ediamin Jan 22, 2020
46fcca7
Introduce the Icons package (#17055)
senadir Jan 22, 2020
1f3ea11
Expose @wordpress/icons to react-native (#19810)
koke Jan 22, 2020
59ed771
Block popover: allow scrolling over (#19769)
ellatrix Jan 22, 2020
938fb55
Multi select: keep selection after move (#19784)
ellatrix Jan 22, 2020
2db504d
Bump plugin version to 7.3.0
ellatrix Jan 22, 2020
c079120
Navigation: Select parent navigation block on handleCreateFromExistin…
jeryj Jan 22, 2020
5a8eda1
Paragraph block: remove dead CSS (#19821)
ellatrix Jan 23, 2020
8acb023
Bundle the icons package instead of using it as an external (#19809)
youknowriad Jan 23, 2020
8f92cfe
Move a dozen of block icons to the icons package (#19808)
youknowriad Jan 23, 2020
6a1ea3c
Chore: Improve package-lock.json configuration
gziolo Jan 23, 2020
373d79a
Add mkevins and pinarol as code owners for gallery block (#19829)
mkevins Jan 23, 2020
0de9e37
Added shippedProposals (#19065)
abdel-h Jan 23, 2020
4ae2c15
Rich text: remove is-selected class (#19822)
ellatrix Jan 23, 2020
26b8015
Move more block SVGs to the icons package (#19834)
youknowriad Jan 23, 2020
89c2b44
Block: use context to provide selected element (#19782)
ellatrix Jan 23, 2020
dcb08f3
Popover: clean up requestAnimationFrame (#19771)
ellatrix Jan 23, 2020
e18e0a0
Update: Removed editor store usage from native mobile block ed… (#18794)
jorgefilipecosta Jan 23, 2020
7704da0
Navigation: Manage navigation link appender visibility based on curre…
jeryj Jan 23, 2020
681a297
Remove editor dependency from the block library (#16160)
jorgefilipecosta Jan 23, 2020
6d035d3
Add AnglePicker Component; Add useDragging hook (#19637)
jorgefilipecosta Jan 23, 2020
f5cdfca
Testing: Use deterministic selectors for incremented IDs (#19844)
aduth Jan 23, 2020
5275570
Innerblock Templates Docs Link Typo Issue Fixed (#19813)
delowardev Jan 23, 2020
17ef62d
Rich text: enable if multi selection is aborted (#19839)
ellatrix Jan 24, 2020
4cd1492
Block Directory: Refactor the reducer by breaking out the block manag…
StevenDufresne Jan 24, 2020
167d4d1
Fix panel header styles (#19842)
adekbadek Jan 24, 2020
b9b1818
Move more block icons to the icons package (#19838)
youknowriad Jan 24, 2020
d2576aa
Bump @babel/preset-env to 7.8.3 (Optional Chaining!) (#19831)
sainthkh Jan 24, 2020
21936b5
Style improvements for template previews (#19763)
koke Jan 24, 2020
605ee4d
[RNMobile] Release v1.21.0 to master (#19854)
etoledom Jan 24, 2020
bc57547
Packages: New create-block package for block scaffolding (#19773)
gziolo Jan 24, 2020
0470286
Pass the prop for selection color. (#19635)
SergioEstevao Jan 24, 2020
282687b
Do not use the deprecated package editor for InnerBlocks component (#…
Mahjouba91 Jan 24, 2020
f6eb4ec
Remove dead is-hovered selectors (#19870)
ellatrix Jan 24, 2020
23493b7
Move is-navigate-mode class to WritingFlow (#19868)
ellatrix Jan 24, 2020
361d2df
[RNmobile] Upgrade to RN 0.61.5 (#19369)
hypest Jan 24, 2020
b3b92f3
Update README.md (#19876)
mkaz Jan 25, 2020
9a364c9
Multi selection: fix intermittent e2e failure (#19865)
ellatrix Jan 25, 2020
b42cde3
Move more block icons to the icons library (#19862)
youknowriad Jan 27, 2020
1fb3c38
Paragraph block: remove min-height (#19835)
ellatrix Jan 27, 2020
e0958d7
Framework: Fix server-registered fixtures script (#19884)
aduth Jan 27, 2020
85ffc72
Shortcode Design Review (#19852)
chipsnyder Jan 27, 2020
288f8df
Update component to components in CONTRIBUTING.md (#19914)
diegohaz Jan 27, 2020
a45df0e
Apply sentence case formatting to PanelBody titles (#19901)
richtabor Jan 27, 2020
64767db
Clarify when isEligible function is called (#19899)
bfintal Jan 27, 2020
c1266a7
Block Editor: Refactor ObserveTyping as function component (#19881)
aduth Jan 27, 2020
9e3c713
Remove unnecessary import from playground (#19893)
costasovo Jan 27, 2020
ba2495f
Documentation: Organize Contributors Guide (#19853)
mkaz Jan 27, 2020
08182bf
[RNMobile] Correct isMobile condition in nested Media&Text (#19778)
lukewalczak Jan 28, 2020
bc38a3d
Blocks: Match blocks in the inserter using keywords from patterns (#1…
gziolo Jan 28, 2020
c49b051
Block editor: Alt+F10 shouldn't scroll to top (#19896)
ellatrix Jan 28, 2020
f6470e6
Multi-selection: fix clearing with side click (#19787)
ellatrix Jan 28, 2020
17f6eae
[RNMobile] fix show appender and separator in Group block (#19908)
jbinda Jan 28, 2020
a911562
Add docs for LocalAutosaveMonitor and __experimentalUpdateLocalAutosa…
mcsf Jan 28, 2020
a38b633
[RNMobile] Add media edit icon to image block (#19723)
leandroalonso Jan 28, 2020
6f97e52
Block Library: Handle Popover onClose for LinkControl (#19885)
aduth Jan 28, 2020
6aa04e8
Disable Autocomplete in shortcode block (#19848)
chipsnyder Jan 28, 2020
1d6895d
RichText API: Limit `prefix` transformations to Paragraph (#19727)
mcsf Jan 28, 2020
4c1ef94
Block Editor: LinkControl: Resolve error when undefined value, "view"…
aduth Jan 28, 2020
a394c9f
[RNMobile] Revert change to fix Action Sheet (#19934)
leandroalonso Jan 28, 2020
e64c554
Add background color support to Columns block (#17813)
richtabor Jan 28, 2020
8c3bd8e
Fix RTL styling for Media Text block (#18764)
richtabor Jan 28, 2020
6987e37
change order of composing style in svg primitive (#19927)
jbinda Jan 29, 2020
c2eece7
Add Prettier formatting script (#18048)
jsnajdr Jan 29, 2020
167bd70
Components: FontSizePicker: Adjust Select Button sizing (#19479)
Jan 29, 2020
b4efa12
Documentation: fix typo "Th" to "The" (#19833)
nekomajin Jan 29, 2020
5cb2727
[RNMobile] Long-press on inserter to show options for "add above" and…
ceyhun Jan 29, 2020
6c8d945
Docs: Add details for format-js to @wordpress/scripts package (#19946)
gziolo Jan 29, 2020
0bda7c4
Fix: Crash when creating a hierarchical post without title (#19936)
jorgefilipecosta Jan 29, 2020
7c32ac9
Fix: Color Gradients component was not able to handle only gra… (#19925)
jorgefilipecosta Jan 29, 2020
ea705dd
Add markdownlint script to lint docs markup (#19855)
mkaz Jan 30, 2020
d17bd4b
Use require.resolve() instead of <rootDir> in @wordpress/jest-preset-…
jameslnewell Jan 30, 2020
5832c30
added changelog entry (#19958)
jameslnewell Jan 30, 2020
06f02c9
Move the insert dashicon to the icons package (#19943)
youknowriad Jan 30, 2020
8497112
Replace all occurences of the yes dashicon with the check icon from t…
youknowriad Jan 30, 2020
e46d52d
Build: Include block.json files in the build output (#19786)
gziolo Jan 30, 2020
d66d53b
Block Editor: LinkControl: Prevent focus loss in edit mode toggle (#1…
aduth Jan 30, 2020
cfa9a97
Move Alignment, movers and trash icons to the icons package (#19944)
youknowriad Jan 30, 2020
c804524
Navigation Block: Move the link description panel below the SEO panel…
apeatling Jan 31, 2020
56d866f
Update hover and focus selectors for Move to Trash to ensure they're …
andrewserong Jan 31, 2020
be05701
Create block: Code quality improvements for the block scaffolding (#1…
gziolo Jan 31, 2020
1b5461c
Code quality: Enable linting for JS files starting with .
gziolo Jan 31, 2020
0194925
Popover: fix typo in removing event listener (#19978)
ellatrix Jan 31, 2020
f63053c
Eslint Plugin: Lint code formatting. (#19963)
epiqueras Jan 31, 2020
63d56f1
[RNMobile] Show the media edit icon only if the block is selected (#1…
leandroalonso Jan 31, 2020
5945e48
Fix: Admin menu collapses for 960px width but editor doesn't (#19970)
jorgefilipecosta Jan 31, 2020
767caac
Chore: Fix differences in package-lock.json file
gziolo Jan 31, 2020
539b1fc
RichText: try using hooks for wrapper component (#19095)
ellatrix Jan 31, 2020
6aa9944
Components: Apply width-based modifier classes to Placeholder only wh…
aduth Jan 31, 2020
4857ad5
Eslint: set line width to 80 (#19992)
ellatrix Jan 31, 2020
fb964cb
Editor: Remove post title escaping (#19955)
aduth Jan 31, 2020
362ab68
Add: Global styles css variables generation mechanism (#19883)
jorgefilipecosta Jan 31, 2020
06bd266
Navigation: Change UX to move focus to navigation link label and clos…
jeryj Jan 31, 2020
d362cb1
Lib: Limit `pre_render_block` extension. (#19989)
epiqueras Feb 1, 2020
80c5239
Fix, update, and sort _rc_ `hasProjectFile` filenames (#19994)
ntwb Feb 2, 2020
b6d8712
Docs: Include CHANGELOG entries from the relocated create-wordpress-b…
gziolo Feb 2, 2020
feed14a
Blocks: Rename patterns to variations in the Block API (#19966)
gziolo Feb 2, 2020
8ef615e
[Mobile] Fix gallery upload sync (#19941)
mkevins Feb 3, 2020
c57bbdb
Merge branch 'rnmobile/releases-2020' into rnmobile/release-v1.22.0-u…
hypest Feb 6, 2020
49e109c
[Mobile] Fix blank image size labels on mobile (#19800) (#20045)
mkevins Feb 6, 2020
fac5718
[RNMobile] Enable Dismiss on PlainText in Android (#20095)
chipsnyder Feb 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[RNMobile] Long-press on inserter to show options for "add above" and…
… "add below" (#18791)

* Add onLongPress prop to Button

* Show inserter menu on long press

* Make onLongPress a prop of toggle

* Make withSelect of Inserter return destinationRootClientId

* Insert default block before the selected one on long press

* Add add canReplaceBlock key to the insertionPoint state

* Hide a block in list only if it can be replaced

* Move insertion index logic from menu to inserter

* Update selector tests for newly added key in state

* Add insertionIndexAfter and isAnyBlockSelected props with selector

* Update docs for newly added key in state

* Add insertionType to component state and map to insertion index

* Refactor insertion index logic

* Show BottomSheet on long press to choose to insert before or after

* Update UI strings to be title case

* Hide cancel button from Bottom Sheet on Android

* Add icons to Bottom Sheet options on Android

* Add “Replace Current Block” option to menu on long-press

* Scroll to newly added block if it doesn't trigger keyboard to open

* Change “Replace Current Block” menu icon on Android

* Use shorter syntax for setState

* Rename getShouldReplaceBlock method to shouldReplaceBlock

* Revert "Scroll to newly added block if it doesn't trigger keyboard to open"

This reverts commit 9c1c71d25eb573427ca09761bd3154286d19539b.

* Revert “Add canReplaceBlock key to the insertionPoint state"

* Remove Block show/hide logic from BlockList

* Update Inserter local state to store block insertion information

* Make InserterMenu add/remove unmodified default block during replace

* Handle replacing last remaining block

* Fix Inserter test

* Fix code style issue

* Move insertion options into getInsertionOptions function

* Add comment about removing last block case

* Use findByProps instead of toJSON when testing Inserter
  • Loading branch information
ceyhun authored Jan 29, 2020
commit 5cb272724b30877217c9ec2d6ee0f4724deb4b51
51 changes: 10 additions & 41 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { View, Platform, TouchableWithoutFeedback } from 'react-native';
import { Component } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import { createBlock } from '@wordpress/blocks';
import { KeyboardAwareFlatList, ReadableContentView } from '@wordpress/components';

/**
Expand Down Expand Up @@ -127,17 +127,9 @@ export class BlockList extends Component {
);
}

isReplaceable( block ) {
if ( ! block ) {
return false;
}
return isUnmodifiedDefaultBlock( block );
}

renderItem( { item: clientId, index } ) {
renderItem( { item: clientId } ) {
const {
isReadOnly,
shouldShowBlockAtIndex,
shouldShowInsertionPointBefore,
shouldShowInsertionPointAfter,
} = this.props;
Expand All @@ -146,15 +138,14 @@ export class BlockList extends Component {
<ReadableContentView>
<View pointerEvents={ isReadOnly ? 'box-only' : 'auto' }>
{ shouldShowInsertionPointBefore( clientId ) && <BlockInsertionPoint /> }
{ shouldShowBlockAtIndex( index ) && (
<BlockListBlock
key={ clientId }
showTitle={ false }
clientId={ clientId }
rootClientId={ this.props.rootClientId }
onCaretVerticalPositionChange={ this.onCaretVerticalPositionChange }
isSmallScreen={ ! this.props.isFullyBordered }
/> ) }
<BlockListBlock
key={ clientId }
showTitle={ false }
clientId={ clientId }
rootClientId={ this.props.rootClientId }
onCaretVerticalPositionChange={ this.onCaretVerticalPositionChange }
isSmallScreen={ ! this.props.isFullyBordered }
/>
{ ! this.shouldShowInnerBlockAppender() && shouldShowInsertionPointAfter( clientId ) && <BlockInsertionPoint /> }
</View>
</ReadableContentView>
Expand All @@ -180,25 +171,17 @@ export default compose( [
withSelect( ( select, { rootClientId } ) => {
const {
getBlockCount,
getBlockIndex,
getBlockOrder,
getSelectedBlockClientId,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
getSelectedBlock,
getSettings,
} = select( 'core/block-editor' );

const {
getGroupingBlockName,
} = select( 'core/blocks' );

const selectedBlockClientId = getSelectedBlockClientId();
const blockClientIds = getBlockOrder( rootClientId );
const insertionPoint = getBlockInsertionPoint();
const blockInsertionPointIsVisible = isBlockInsertionPointVisible();
const selectedBlock = getSelectedBlock();
const hasInnerBlocks = selectedBlock && selectedBlock.name === getGroupingBlockName();
const shouldShowInsertionPointBefore = ( clientId ) => {
return (
blockInsertionPointIsVisible &&
Expand All @@ -224,26 +207,12 @@ export default compose( [
);
};

const selectedBlockIndex = getBlockIndex( selectedBlockClientId, rootClientId );

const shouldShowBlockAtIndex = ( index ) => {
const shouldHideBlockAtIndex = (
! hasInnerBlocks && blockInsertionPointIsVisible &&
// if `index` === `insertionPoint.index`, then block is replaceable
index === insertionPoint.index &&
// only hide selected block
index === selectedBlockIndex
);
return ! shouldHideBlockAtIndex;
};

const isReadOnly = getSettings().readOnly;

return {
blockClientIds,
blockCount: getBlockCount( rootClientId ),
isBlockInsertionPointVisible: isBlockInsertionPointVisible(),
shouldShowBlockAtIndex,
shouldShowInsertionPointBefore,
shouldShowInsertionPointAfter,
selectedBlockClientId,
Expand Down
203 changes: 187 additions & 16 deletions packages/block-editor/src/components/inserter/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Dropdown, ToolbarButton, Dashicon } from '@wordpress/components';
import { Dropdown, ToolbarButton, Dashicon, Picker } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { getUnregisteredTypeHandlerName } from '@wordpress/blocks';
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -15,7 +15,7 @@ import styles from './style.scss';
import InserterMenu from './menu';
import BlockInsertionPoint from '../block-list/insertion-point';

const defaultRenderToggle = ( { onToggle, disabled, style } ) => (
const defaultRenderToggle = ( { onToggle, disabled, style, onLongPress } ) => (
<ToolbarButton
title={ __( 'Add block' ) }
icon={ ( <Dashicon icon="plus-alt" style={ style } color={ style.color } /> ) }
Expand All @@ -25,12 +25,13 @@ const defaultRenderToggle = ( { onToggle, disabled, style } ) => (
// testID is present to disambiguate this element for native UI tests. It's not
// usually required for components. See: https://git.io/JeQ7G.
testID: 'add-block-button',
onLongPress,
} }
isDisabled={ disabled }
/>
);

class Inserter extends Component {
export class Inserter extends Component {
constructor() {
super( ...arguments );

Expand All @@ -39,6 +40,75 @@ class Inserter extends Component {
this.renderContent = this.renderContent.bind( this );
}

getInsertionOptions() {
const addBeforeOption = {
value: 'before',
label: __( 'Add Block Before' ),
icon: 'insert-before',
};

const replaceCurrentOption = {
value: 'replace',
label: __( 'Replace Current Block' ),
icon: 'plus-alt',
};

const addAfterOption = {
value: 'after',
label: __( 'Add Block After' ),
icon: 'insert-after',
};

const addToBeginningOption = {
value: 'before',
label: __( 'Add To Beginning' ),
icon: 'insert-before',
};

const addToEndOption = {
value: 'after',
label: __( 'Add To End' ),
icon: 'insert-after',
};

const { isAnyBlockSelected, isSelectedBlockReplaceable } = this.props;
if ( isAnyBlockSelected ) {
if ( isSelectedBlockReplaceable ) {
return [ addBeforeOption, replaceCurrentOption, addAfterOption ];
}
return [ addBeforeOption, addAfterOption ];
}
return [ addToBeginningOption, addToEndOption ];
}

getInsertionIndex( insertionType ) {
const {
insertionIndexDefault,
insertionIndexBefore,
insertionIndexAfter,
} = this.props;
if ( insertionType === 'before' || insertionType === 'replace' ) {
return insertionIndexBefore;
}
if ( insertionType === 'after' ) {
return insertionIndexAfter;
}
return insertionIndexDefault;
}

shouldReplaceBlock( insertionType ) {
const {
isSelectedBlockReplaceable,
} = this.props;
if ( insertionType === 'replace' ) {
return true;
}
if ( insertionType === 'default' && isSelectedBlockReplaceable ) {
return true;
}
return false;
}

onToggle( isOpen ) {
const { onToggle } = this.props;

Expand Down Expand Up @@ -69,7 +139,46 @@ class Inserter extends Component {
return <BlockInsertionPoint />;
}
const style = getStylesFromColorScheme( styles.addBlockButton, styles.addBlockButtonDark );
return renderToggle( { onToggle, isOpen, disabled, style } );

const onPress = () => {
this.setState( {
destinationRootClientId: this.props.destinationRootClientId,
shouldReplaceBlock: this.shouldReplaceBlock( 'default' ),
insertionIndex: this.getInsertionIndex( 'default' ),
}, onToggle );
};

const onLongPress = () => {
if ( this.picker ) {
this.picker.presentPicker();
}
};

const onPickerSelect = ( insertionType ) => {
this.setState( {
destinationRootClientId: this.props.destinationRootClientId,
shouldReplaceBlock: this.shouldReplaceBlock( insertionType ),
insertionIndex: this.getInsertionIndex( insertionType ),
}, onToggle );
};

return (
<>
{ renderToggle( {
onToggle: onPress,
isOpen,
disabled,
style,
onLongPress,
} ) }
<Picker
ref={ ( instance ) => ( this.picker = instance ) }
options={ this.getInsertionOptions() }
onChange={ onPickerSelect }
hideCancelButton
/>
</>
);
}

/**
Expand All @@ -82,16 +191,25 @@ class Inserter extends Component {
* @return {WPElement} Dropdown content element.
*/
renderContent( { onClose, isOpen } ) {
const { rootClientId, clientId, isAppender } = this.props;

const {
clientId,
isAppender,
} = this.props;
const {
destinationRootClientId,
shouldReplaceBlock,
insertionIndex,
} = this.state;
return (
<InserterMenu
isOpen={ isOpen }
onSelect={ onClose }
onDismiss={ onClose }
rootClientId={ rootClientId }
rootClientId={ destinationRootClientId }
clientId={ clientId }
isAppender={ isAppender }
shouldReplaceBlock={ shouldReplaceBlock }
insertionIndex={ insertionIndex }
/>
);
}
Expand All @@ -111,23 +229,76 @@ class Inserter extends Component {
export default compose( [
withSelect( ( select, { clientId, isAppender, rootClientId } ) => {
const {
getInserterItems,
getBlockRootClientId,
getBlockSelectionEnd,
getBlockOrder,
getBlockIndex,
getBlock,
} = select( 'core/block-editor' );

let destinationRootClientId = rootClientId;
if ( ! destinationRootClientId && ! clientId && ! isAppender ) {
const end = getBlockSelectionEnd();
if ( end ) {
destinationRootClientId = getBlockRootClientId( end ) || undefined;
const end = getBlockSelectionEnd();
// `end` argument (id) can refer to the component which is removed
// due to pressing `undo` button, that's why we need to check
// if `getBlock( end) is valid, otherwise `null` is passed
const isAnyBlockSelected = ( ! isAppender && end && getBlock( end ) );
const destinationRootClientId = isAnyBlockSelected ?
getBlockRootClientId( end ) :
rootClientId;
const selectedBlockIndex = getBlockIndex( end, destinationRootClientId );
const endOfRootIndex = getBlockOrder( rootClientId ).length;
const isSelectedUnmodifiedDefaultBlock = isAnyBlockSelected ?
isUnmodifiedDefaultBlock( getBlock( end ) ) :
undefined;

function getDefaultInsertionIndex() {
const {
getSettings,
} = select( 'core/block-editor' );

const { __experimentalShouldInsertAtTheTop: shouldInsertAtTheTop } = getSettings();

// if post title is selected insert as first block
if ( shouldInsertAtTheTop ) {
return 0;
}

// If the clientId is defined, we insert at the position of the block.
if ( clientId ) {
return getBlockIndex( clientId, rootClientId );
}

// If there is a selected block,
if ( isAnyBlockSelected ) {
// and the last selected block is unmodified (empty), it will be replaced
if ( isSelectedUnmodifiedDefaultBlock ) {
return selectedBlockIndex;
}

// we insert after the selected block.
return selectedBlockIndex + 1;
}

// Otherwise, we insert at the end of the current rootClientId
return endOfRootIndex;
}
const inserterItems = getInserterItems( destinationRootClientId );

const insertionIndexBefore = isAnyBlockSelected ?
selectedBlockIndex :
0;

const insertionIndexAfter = isAnyBlockSelected ?
selectedBlockIndex + 1 :
endOfRootIndex;

return {
items: inserterItems.filter( ( { name } ) => name !== getUnregisteredTypeHandlerName() ),
destinationRootClientId,
insertionIndexDefault: getDefaultInsertionIndex(),
insertionIndexBefore,
insertionIndexAfter,
isAnyBlockSelected,
isSelectedBlockReplaceable: isSelectedUnmodifiedDefaultBlock,
};
} ),

withPreferredColorScheme,
] )( Inserter );
Loading