Skip to content

Commit

Permalink
Switch disable to block-editor store
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaz committed Jul 16, 2020
1 parent 54043d3 commit ccb12e1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Expand Up @@ -481,6 +481,7 @@ _Properties_
- _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
- _disableImageEditor_ `boolean`: Whether or not the Image Editor is disabled.
- _imageSizes_ `Array`: Available image sizes
- _maxWidth_ `number`: Max width to constraint resizing
- _allowedBlockTypes_ `(boolean|Array)`: Allowed block types
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/defaults.js
Expand Up @@ -17,6 +17,7 @@ export const PREFERENCES_DEFAULTS = {
* @property {boolean} disableCustomColors Whether or not the custom colors are disabled
* @property {Array} fontSizes Available font sizes
* @property {boolean} disableCustomFontSizes Whether or not the custom font sizes are disabled
* @property {boolean} disableImageEditor Whether or not the Image Editor is disabled.
* @property {Array} imageSizes Available image sizes
* @property {number} maxWidth Max width to constraint resizing
* @property {boolean|Array} allowedBlockTypes Allowed block types
Expand Down Expand Up @@ -131,6 +132,9 @@ export const SETTINGS_DEFAULTS = {
{ slug: 'full', name: __( 'Full Size' ) },
],

// Allow plugin to disable Image Editor if need be
disableImageEditor: false,

// This is current max width of the block inner area
// It's used to constraint image resizing and this value could be overridden later by themes
maxWidth: 580,
Expand Down
31 changes: 18 additions & 13 deletions packages/block-library/src/image/image.js
Expand Up @@ -87,17 +87,22 @@ export default function Image( {
},
[ id, isSelected ]
);
const { maxWidth, isRTL, imageSizes, mediaUpload } = useSelect(
( select ) => {
const { getSettings } = select( 'core/block-editor' );
return pick( getSettings(), [
'imageSizes',
'isRTL',
'maxWidth',
'mediaUpload',
] );
}
);
const {
imageSizes,
disableImageEditor,
isRTL,
maxWidth,
mediaUpload,
} = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
return pick( getSettings(), [
'imageSizes',
'disableImageEditor',
'isRTL',
'maxWidth',
'mediaUpload',
] );
} );
const { toggleSelection } = useDispatch( 'core/block-editor' );
const { createErrorNotice, createSuccessNotice } = useDispatch(
'core/notices'
Expand Down Expand Up @@ -226,8 +231,8 @@ export default function Image( {
}
}, [ isSelected ] );

const isEditorEnabled = ! window._wpImageEditorDisabled;
const canEditImage = id && naturalWidth && naturalHeight && isEditorEnabled;
const canEditImage =
id && naturalWidth && naturalHeight && ! disableImageEditor;

const controls = (
<>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/provider/index.js
Expand Up @@ -133,6 +133,7 @@ class EditorProvider extends Component {
'disableCustomColors',
'disableCustomFontSizes',
'disableCustomGradients',
'disableImageEditor',
'enableCustomUnits',
'enableCustomLineHeight',
'focusMode',
Expand Down

0 comments on commit ccb12e1

Please sign in to comment.