-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the block components to the block editor module
- Loading branch information
1 parent
05570ff
commit 98ac800
Showing
318 changed files
with
442 additions
and
362 deletions.
There are no files selected for viewing
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
160 changes: 160 additions & 0 deletions
160
packages/block-editor/src/components/block-editor-keyboard-shortcuts/index.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,160 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { first, last, some, flow } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component, Fragment } from '@wordpress/element'; | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { rawShortcut, displayShortcut } from '@wordpress/keycodes'; | ||
import { compose } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockActions from '../block-actions'; | ||
|
||
const preventDefault = ( event ) => { | ||
event.preventDefault(); | ||
return event; | ||
}; | ||
|
||
export const shortcuts = { | ||
duplicate: { | ||
raw: rawShortcut.primaryShift( 'd' ), | ||
display: displayShortcut.primaryShift( 'd' ), | ||
}, | ||
removeBlock: { | ||
raw: rawShortcut.access( 'z' ), | ||
display: displayShortcut.access( 'z' ), | ||
}, | ||
insertBefore: { | ||
raw: rawShortcut.primaryAlt( 't' ), | ||
display: displayShortcut.primaryAlt( 't' ), | ||
}, | ||
insertAfter: { | ||
raw: rawShortcut.primaryAlt( 'y' ), | ||
display: displayShortcut.primaryAlt( 'y' ), | ||
}, | ||
}; | ||
|
||
class BlockEditorKeyboardShortcuts extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.selectAll = this.selectAll.bind( this ); | ||
this.deleteSelectedBlocks = this.deleteSelectedBlocks.bind( this ); | ||
this.clearMultiSelection = this.clearMultiSelection.bind( this ); | ||
} | ||
|
||
selectAll( event ) { | ||
const { rootBlocksClientIds, onMultiSelect } = this.props; | ||
event.preventDefault(); | ||
onMultiSelect( first( rootBlocksClientIds ), last( rootBlocksClientIds ) ); | ||
} | ||
|
||
deleteSelectedBlocks( event ) { | ||
const { selectedBlockClientIds, hasMultiSelection, onRemove, isLocked } = this.props; | ||
if ( hasMultiSelection ) { | ||
event.preventDefault(); | ||
if ( ! isLocked ) { | ||
onRemove( selectedBlockClientIds ); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Clears current multi-selection, if one exists. | ||
*/ | ||
clearMultiSelection() { | ||
const { hasMultiSelection, clearSelectedBlock } = this.props; | ||
if ( hasMultiSelection ) { | ||
clearSelectedBlock(); | ||
window.getSelection().removeAllRanges(); | ||
} | ||
} | ||
|
||
render() { | ||
const { selectedBlockClientIds } = this.props; | ||
return ( | ||
<Fragment> | ||
<KeyboardShortcuts | ||
shortcuts={ { | ||
[ rawShortcut.primary( 'a' ) ]: this.selectAll, | ||
backspace: this.deleteSelectedBlocks, | ||
del: this.deleteSelectedBlocks, | ||
escape: this.clearMultiSelection, | ||
} } | ||
/> | ||
{ selectedBlockClientIds.length > 0 && ( | ||
<BlockActions clientIds={ selectedBlockClientIds }> | ||
{ ( { onDuplicate, onRemove, onInsertAfter, onInsertBefore } ) => ( | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
// Prevents bookmark all Tabs shortcut in Chrome when devtools are closed. | ||
// Prevents reposition Chrome devtools pane shortcut when devtools are open. | ||
[ shortcuts.duplicate.raw ]: flow( preventDefault, onDuplicate ), | ||
|
||
// Does not clash with any known browser/native shortcuts, but preventDefault | ||
// is used to prevent any obscure unknown shortcuts from triggering. | ||
[ shortcuts.removeBlock.raw ]: flow( preventDefault, onRemove ), | ||
|
||
// Prevent 'view recently closed tabs' in Opera using preventDefault. | ||
[ shortcuts.insertBefore.raw ]: flow( preventDefault, onInsertBefore ), | ||
|
||
// Does not clash with any known browser/native shortcuts, but preventDefault | ||
// is used to prevent any obscure unknown shortcuts from triggering. | ||
[ shortcuts.insertAfter.raw ]: flow( preventDefault, onInsertAfter ), | ||
} } | ||
/> | ||
) } | ||
</BlockActions> | ||
) } | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
const EnhancedVisualEditorGlobalKeyboardShortcuts = compose( [ | ||
withSelect( ( select ) => { | ||
const { | ||
getBlockOrder, | ||
getMultiSelectedBlockClientIds, | ||
hasMultiSelection, | ||
getBlockRootClientId, | ||
getTemplateLock, | ||
getSelectedBlockClientId, | ||
} = select( 'core/block-editor' ); | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
const selectedBlockClientIds = selectedBlockClientId ? [ selectedBlockClientId ] : getMultiSelectedBlockClientIds(); | ||
|
||
return { | ||
rootBlocksClientIds: getBlockOrder(), | ||
hasMultiSelection: hasMultiSelection(), | ||
isLocked: some( | ||
selectedBlockClientIds, | ||
( clientId ) => !! getTemplateLock( getBlockRootClientId( clientId ) ) | ||
), | ||
selectedBlockClientIds, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
const { | ||
clearSelectedBlock, | ||
multiSelect, | ||
removeBlocks, | ||
} = dispatch( 'core/block-editor' ); | ||
|
||
return { | ||
clearSelectedBlock, | ||
onMultiSelect: multiSelect, | ||
onRemove: removeBlocks, | ||
}; | ||
} ), | ||
] )( BlockEditorKeyboardShortcuts ); | ||
|
||
export default EnhancedVisualEditorGlobalKeyboardShortcuts; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1 +1,58 @@ | ||
// Block Creation Components | ||
export { default as Autocomplete } from './autocomplete'; | ||
export { default as AlignmentToolbar } from './alignment-toolbar'; | ||
export { default as BlockAlignmentToolbar } from './block-alignment-toolbar'; | ||
export { default as BlockControls } from './block-controls'; | ||
export { default as BlockEdit } from './block-edit'; | ||
export { default as BlockFormatControls } from './block-format-controls'; | ||
export { default as BlockNavigationDropdown } from './block-navigation/dropdown'; | ||
export { default as BlockIcon } from './block-icon'; | ||
export { default as ColorPalette } from './color-palette'; | ||
export { default as withColorContext } from './color-palette/with-color-context'; | ||
export * from './colors'; | ||
export { default as ContrastChecker } from './contrast-checker'; | ||
export * from './font-sizes'; | ||
export { default as InnerBlocks } from './inner-blocks'; | ||
export { default as InspectorAdvancedControls } from './inspector-advanced-controls'; | ||
export { default as InspectorControls } from './inspector-controls'; | ||
export { default as PanelColorSettings } from './panel-color-settings'; | ||
export { default as PlainText } from './plain-text'; | ||
export { | ||
default as RichText, | ||
RichTextShortcut, | ||
RichTextToolbarButton, | ||
RichTextInserterItem, | ||
UnstableRichTextInputEvent, | ||
} from './rich-text'; | ||
export { default as MediaPlaceholder } from './media-placeholder'; | ||
export { default as MediaUpload } from './media-upload'; | ||
export { default as MediaUploadCheck } from './media-upload/check'; | ||
export { default as URLInput } from './url-input'; | ||
export { default as URLInputButton } from './url-input/button'; | ||
export { default as URLPopover } from './url-popover'; | ||
|
||
// Content Related Components | ||
export { default as BlockEditorKeyboardShortcuts } from './block-editor-keyboard-shortcuts'; | ||
export { default as BlockInspector } from './block-inspector'; | ||
export { default as BlockList } from './block-list'; | ||
export { default as BlockMover } from './block-mover'; | ||
export { default as BlockSelectionClearer } from './block-selection-clearer'; | ||
export { default as BlockSettingsMenu } from './block-settings-menu'; | ||
export { default as _BlockSettingsMenuFirstItem } from './block-settings-menu/block-settings-menu-first-item'; | ||
export { default as _BlockSettingsMenuPluginsExtension } from './block-settings-menu/block-settings-menu-plugins-extension'; | ||
export { default as BlockTitle } from './block-title'; | ||
export { default as BlockToolbar } from './block-toolbar'; | ||
export { default as CopyHandler } from './copy-handler'; | ||
export { default as DefaultBlockAppender } from './default-block-appender'; | ||
export { default as Inserter } from './inserter'; | ||
export { default as MultiBlocksSwitcher } from './block-switcher/multi-blocks-switcher'; | ||
export { default as MultiSelectScrollIntoView } from './multi-select-scroll-into-view'; | ||
export { default as NavigableToolbar } from './navigable-toolbar'; | ||
export { default as ObserveTyping } from './observe-typing'; | ||
export { default as PreserveScrollInReorder } from './preserve-scroll-in-reorder'; | ||
export { default as SkipToSelectedBlock } from './skip-to-selected-block'; | ||
export { default as Warning } from './warning'; | ||
export { default as WritingFlow } from './writing-flow'; | ||
|
||
// State Related Components | ||
export { default as BlockEditorProvider } from './provider'; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,7 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './align'; | ||
import './anchor'; | ||
import './custom-class-name'; | ||
import './generated-class-name'; |
Oops, something went wrong.