Skip to content

Commit

Permalink
Remove usage of select editor from the block editor module (#16184)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Jul 10, 2019
1 parent 1731607 commit 5756b29
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 40 deletions.
35 changes: 18 additions & 17 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,24 @@ Undocumented declaration.

The default editor settings

alignWide boolean Enable/Disable Wide/Full Alignments
availableLegacyWidgets Array Array of objects representing the legacy widgets available.
colors Array Palette colors
disableCustomColors boolean Whether or not the custom colors are disabled
fontSizes Array Available font sizes
disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
imageSizes Array Available image sizes
maxWidth number Max width to constraint resizing
allowedBlockTypes boolean|Array Allowed block types
hasFixedToolbar boolean Whether or not the editor toolbar is fixed
hasPermissionsToManageWidgets boolean Whether or not the user is able to manage widgets.
focusMode boolean Whether the focus mode is enabled or not
styles Array Editor Styles
isRTL boolean Whether the editor is in RTL mode
bodyPlaceholder string Empty post placeholder
titlePlaceholder string Empty title placeholder
codeEditingEnabled string Whether or not the user can switch to the code editor
alignWide boolean Enable/Disable Wide/Full Alignments
availableLegacyWidgets Array Array of objects representing the legacy widgets available.
colors Array Palette colors
disableCustomColors boolean Whether or not the custom colors are disabled
fontSizes Array Available font sizes
disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
imageSizes Array Available image sizes
maxWidth number Max width to constraint resizing
allowedBlockTypes boolean|Array Allowed block types
hasFixedToolbar boolean Whether or not the editor toolbar is fixed
hasPermissionsToManageWidgets boolean Whether or not the user is able to manage widgets.
focusMode boolean Whether the focus mode is enabled or not
styles Array Editor Styles
isRTL boolean Whether the editor is in RTL mode
bodyPlaceholder string Empty post placeholder
titlePlaceholder string Empty title placeholder
codeEditingEnabled string Whether or not the user can switch to the code editor
\_\_experimentalCanUserUseUnfilteredHTML string Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.

<a name="SkipToSelectedBlock" href="#SkipToSelectedBlock">#</a> **SkipToSelectedBlock**

Expand Down
7 changes: 3 additions & 4 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,16 @@ const RichTextContainer = compose( [
identifier = instanceId,
isSelected,
} ) => {
// This should probably be moved to the block editor settings.
const { canUserUseUnfilteredHTML } = select( 'core/editor' );
const {
isCaretWithinFormattedText,
getSelectionStart,
getSelectionEnd,
getSettings,
} = select( 'core/block-editor' );

const selectionStart = getSelectionStart();
const selectionEnd = getSelectionEnd();

const { __experimentalCanUserUseUnfilteredHTML } = getSettings();
if ( isSelected === undefined ) {
isSelected = (
selectionStart.clientId === clientId &&
Expand All @@ -389,7 +388,7 @@ const RichTextContainer = compose( [
}

return {
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(),
canUserUseUnfilteredHTML: __experimentalCanUserUseUnfilteredHTML,
isCaretWithinFormattedText: isCaretWithinFormattedText(),
selectionStart: isSelected ? selectionStart.offset : undefined,
selectionEnd: isSelected ? selectionEnd.offset : undefined,
Expand Down
36 changes: 19 additions & 17 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ export const PREFERENCES_DEFAULTS = {
/**
* The default editor settings
*
* alignWide boolean Enable/Disable Wide/Full Alignments
* availableLegacyWidgets Array Array of objects representing the legacy widgets available.
* colors Array Palette colors
* disableCustomColors boolean Whether or not the custom colors are disabled
* fontSizes Array Available font sizes
* disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* allowedBlockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* hasPermissionsToManageWidgets boolean Whether or not the user is able to manage widgets.
* focusMode boolean Whether the focus mode is enabled or not
* styles Array Editor Styles
* isRTL boolean Whether the editor is in RTL mode
* bodyPlaceholder string Empty post placeholder
* titlePlaceholder string Empty title placeholder
* codeEditingEnabled string Whether or not the user can switch to the code editor
* alignWide boolean Enable/Disable Wide/Full Alignments
* availableLegacyWidgets Array Array of objects representing the legacy widgets available.
* colors Array Palette colors
* disableCustomColors boolean Whether or not the custom colors are disabled
* fontSizes Array Available font sizes
* disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* allowedBlockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* hasPermissionsToManageWidgets boolean Whether or not the user is able to manage widgets.
* focusMode boolean Whether the focus mode is enabled or not
* styles Array Editor Styles
* isRTL boolean Whether the editor is in RTL mode
* bodyPlaceholder string Empty post placeholder
* titlePlaceholder string Empty title placeholder
* codeEditingEnabled string Whether or not the user can switch to the code editor
* __experimentalCanUserUseUnfilteredHTML string Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.
*/
export const SETTINGS_DEFAULTS = {
alignWide: false,
Expand Down Expand Up @@ -137,5 +138,6 @@ export const SETTINGS_DEFAULTS = {

availableLegacyWidgets: {},
hasPermissionsToManageWidgets: false,
__experimentalCanUserUseUnfilteredHTML: false,
};

20 changes: 18 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ class EditorProvider extends Component {
}
}

getBlockEditorSettings( settings, meta, onMetaChange, reusableBlocks, hasUploadPermissions ) {
getBlockEditorSettings(
settings,
meta,
onMetaChange,
reusableBlocks,
hasUploadPermissions,
canUserUseUnfilteredHTML
) {
return {
...pick( settings, [
'alignWide',
Expand Down Expand Up @@ -102,6 +109,7 @@ class EditorProvider extends Component {
__experimentalReusableBlocks: reusableBlocks,
__experimentalMediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalFetchLinkSuggestions: fetchLinkSuggestions,
__experimentalCanUserUseUnfilteredHTML: canUserUseUnfilteredHTML,
};
}

Expand Down Expand Up @@ -131,6 +139,7 @@ class EditorProvider extends Component {

render() {
const {
canUserUseUnfilteredHTML,
children,
blocks,
resetEditorBlocks,
Expand All @@ -148,7 +157,12 @@ class EditorProvider extends Component {
}

const editorSettings = this.getBlockEditorSettings(
settings, meta, onMetaChange, reusableBlocks, hasUploadPermissions
settings,
meta,
onMetaChange,
reusableBlocks,
hasUploadPermissions,
canUserUseUnfilteredHTML
);

return (
Expand All @@ -171,6 +185,7 @@ export default compose( [
withRegistryProvider,
withSelect( ( select ) => {
const {
canUserUseUnfilteredHTML,
__unstableIsEditorReady: isEditorReady,
getEditorBlocks,
getEditedPostAttribute,
Expand All @@ -179,6 +194,7 @@ export default compose( [
const { canUser } = select( 'core' );

return {
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(),
isReady: isEditorReady(),
blocks: getEditorBlocks(),
meta: getEditedPostAttribute( 'meta' ),
Expand Down

0 comments on commit 5756b29

Please sign in to comment.