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

Remove usage of select editor from the block editor module #16184

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -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 &&
Expand All @@ -154,7 +153,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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you think this shhould be experimental?
Also these settings are documented in the defaults.js file of the block-editor package in addition to providing the default value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @youknowriad the default.js file was updated, nice catch.
The setting was only marked as experimental because lately all new additions were kept experimental for one version so I followed the same logic, but I can change it.

};
}

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