From 16c677a1cd126236bf52a61b86d6ad4cbce7ca87 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 14 Jun 2019 17:12:13 +0100 Subject: [PATCH] Remove usage of select editor from the block editor module --- packages/block-editor/README.md | 35 +++++++++--------- .../src/components/rich-text/index.js | 7 ++-- packages/block-editor/src/store/defaults.js | 36 ++++++++++--------- .../editor/src/components/provider/index.js | 20 +++++++++-- 4 files changed, 58 insertions(+), 40 deletions(-) diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index f279d2994600d3..63718286e9bb87 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -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. # **SkipToSelectedBlock** diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 8f96935d549895..40a43000f4f12a 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -135,17 +135,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 && @@ -154,7 +153,7 @@ const RichTextContainer = compose( [ } return { - canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), + canUserUseUnfilteredHTML: __experimentalCanUserUseUnfilteredHTML, isCaretWithinFormattedText: isCaretWithinFormattedText(), selectionStart: isSelected ? selectionStart.offset : undefined, selectionEnd: isSelected ? selectionEnd.offset : undefined, diff --git a/packages/block-editor/src/store/defaults.js b/packages/block-editor/src/store/defaults.js index 49cf289b58e0d6..dc950c9a426deb 100644 --- a/packages/block-editor/src/store/defaults.js +++ b/packages/block-editor/src/store/defaults.js @@ -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, @@ -137,5 +138,6 @@ export const SETTINGS_DEFAULTS = { availableLegacyWidgets: {}, hasPermissionsToManageWidgets: false, + __experimentalCanUserUseUnfilteredHTML: false, }; diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index cc9533a0a79a7b..d241aedac6fd5b 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -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', @@ -102,6 +109,7 @@ class EditorProvider extends Component { __experimentalReusableBlocks: reusableBlocks, __experimentalMediaUpload: hasUploadPermissions ? mediaUpload : undefined, __experimentalFetchLinkSuggestions: fetchLinkSuggestions, + __experimentalCanUserUseUnfilteredHTML: canUserUseUnfilteredHTML, }; } @@ -131,6 +139,7 @@ class EditorProvider extends Component { render() { const { + canUserUseUnfilteredHTML, children, blocks, resetEditorBlocks, @@ -148,7 +157,12 @@ class EditorProvider extends Component { } const editorSettings = this.getBlockEditorSettings( - settings, meta, onMetaChange, reusableBlocks, hasUploadPermissions + settings, + meta, + onMetaChange, + reusableBlocks, + hasUploadPermissions, + canUserUseUnfilteredHTML ); return ( @@ -171,6 +185,7 @@ export default compose( [ withRegistryProvider, withSelect( ( select ) => { const { + canUserUseUnfilteredHTML, __unstableIsEditorReady: isEditorReady, getEditorBlocks, getEditedPostAttribute, @@ -179,6 +194,7 @@ export default compose( [ const { canUser } = select( 'core' ); return { + canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), isReady: isEditorReady(), blocks: getEditorBlocks(), meta: getEditedPostAttribute( 'meta' ),