Skip to content

Commit

Permalink
Revert useSetting shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jun 8, 2021
1 parent b4bea45 commit d3cdc67
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 193 deletions.
10 changes: 2 additions & 8 deletions packages/block-editor/src/components/block-list/block.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import {
getBlockType,
__experimentalGetAccessibleBlockLabel as getAccessibleBlockLabel,
} from '@wordpress/blocks';
import {
useSetting,
__experimentalGetHighestPriorityPreset,
} from '@wordpress/block-editor';
import { useSetting } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,10 +49,7 @@ function BlockForType( {
wrapperProps,
blockWidth,
} ) {
const defaultColors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || emptyArray;
const defaultColors = useSetting( 'color.palette' ) || emptyArray;
const globalStyle = useGlobalStyles();
const mergedStyle = useMemo( () => {
return getMergedGlobalStyles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ import { createHigherOrderComponent } from '@wordpress/compose';
* Internal dependencies
*/
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

export default createHigherOrderComponent( ( WrappedComponent ) => {
return ( props ) => {
const colorsFeature = __experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
);
const colorsFeature = useSetting( 'color.palette' );
const disableCustomColorsFeature = ! useSetting( 'color.custom' );
const colors =
props.colors === undefined ? colorsFeature : props.colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { sprintf, __ } from '@wordpress/i18n';
import { getColorObjectByColorValue } from '../colors';
import { __experimentalGetGradientObjectByGradientValue } from '../gradients';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

// translators: first %s: the color name or value (e.g. red or #ff0000)
const colorIndicatorAriaLabel = __( '(Color: %s)' );
Expand Down Expand Up @@ -178,12 +177,8 @@ function ColorGradientControlInner( {

function ColorGradientControlSelect( props ) {
const colorGradientSettings = {};
colorGradientSettings.colors = __experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
);
colorGradientSettings.gradients = __experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
);
colorGradientSettings.colors = useSetting( 'color.palette' );
colorGradientSettings.gradients = useSetting( 'color.gradients' );
colorGradientSettings.disableCustomColors = ! useSetting( 'color.custom' );
colorGradientSettings.disableCustomGradients = ! useSetting(
'color.customGradient'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ColorGradientControl from './control';
import { getColorObjectByColorValue } from '../colors';
import { __experimentalGetGradientObjectByGradientValue } from '../gradients';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

// translators: first %s: The type of color or gradient (e.g. background, overlay...), second %s: the color name or value (e.g. red or #ff0000)
const colorIndicatorAriaLabel = __( '(%s: color %s)' );
Expand Down Expand Up @@ -149,12 +148,8 @@ export const PanelColorGradientSettingsInner = ( {

const PanelColorGradientSettingsSelect = ( props ) => {
const colorGradientSettings = {};
colorGradientSettings.colors = __experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
);
colorGradientSettings.gradients = __experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
);
colorGradientSettings.colors = useSetting( 'color.palette' );
colorGradientSettings.gradients = useSetting( 'color.gradients' );
colorGradientSettings.disableCustomColors = ! useSetting( 'color.custom' );
colorGradientSettings.disableCustomGradients = ! useSetting(
'color.customGradient'
Expand Down
6 changes: 1 addition & 5 deletions packages/block-editor/src/components/colors/with-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getMostReadableColor,
} from './utils';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

const DEFAULT_COLORS = [];

Expand Down Expand Up @@ -48,10 +47,7 @@ const withCustomColorPalette = ( colorsArray ) =>
const withEditorColorPalette = () =>
createHigherOrderComponent(
( WrappedComponent ) => ( props ) => {
const colors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || DEFAULT_COLORS;
const colors = useSetting( 'color.palette' ) || DEFAULT_COLORS;
return <WrappedComponent { ...props } colors={ colors } />;
},
'withEditorColorPalette'
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/font-family/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

export default function FontFamilyControl( {
value = '',
onChange,
fontFamilies,
...props
} ) {
const blockLevelFontFamilies = __experimentalGetHighestPriorityPreset(
useSetting( 'typography.fontFamilies' )
);
const blockLevelFontFamilies = useSetting( 'typography.fontFamilies' );
if ( ! fontFamilies ) {
fontFamilies = blockLevelFontFamilies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import { FontSizePicker as BaseFontSizePicker } from '@wordpress/components';
* Internal dependencies
*/
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

function FontSizePicker( props ) {
const fontSizes = __experimentalGetHighestPriorityPreset(
useSetting( 'typography.fontSizes' )
);
const fontSizes = useSetting( 'typography.fontSizes' );
const disableCustomFontSizes = ! useSetting( 'typography.customFontSize' );

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Component } from '@wordpress/element';
*/
import { getFontSize, getFontSizeClass } from './utils';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

const DEFAULT_FONT_SIZES = [];

Expand Down Expand Up @@ -50,9 +49,8 @@ export default ( ...fontSizeNames ) => {
createHigherOrderComponent(
( WrappedComponent ) => ( props ) => {
const fontSizes =
__experimentalGetHighestPriorityPreset(
useSetting( 'typography.fontSizes' )
) || DEFAULT_FONT_SIZES;
useSetting( 'typography.fontSizes' ) ||
DEFAULT_FONT_SIZES;
return (
<WrappedComponent
{ ...props }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { __ } from '@wordpress/i18n';
*/
import GradientPicker from './';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

export default function GradientPickerControl( {
className,
Expand All @@ -24,9 +23,7 @@ export default function GradientPickerControl( {
label = __( 'Gradient Presets' ),
...props
} ) {
const gradients = __experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
);
const gradients = useSetting( 'color.gradients' );
const disableCustomGradients = ! useSetting( 'color.customGradient' );
if ( isEmpty( gradients ) && disableCustomGradients ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { __experimentalGradientPicker as GradientPicker } from '@wordpress/compo
* Internal dependencies
*/
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

const EMPTY_ARRAY = [];

function GradientPickerWithGradients( props ) {
const gradients =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
) || EMPTY_ARRAY;
const gradients = useSetting( 'color.gradients' ) || EMPTY_ARRAY;
const disableCustomGradients = ! useSetting( 'color.customGradient' );

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import { __ } from '@wordpress/i18n';
*/
import GradientPicker from './control';
import useSetting from '../use-setting';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

export default function GradientPanel( props ) {
const gradients = __experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
);
const gradients = useSetting( 'color.gradients' );
if ( isEmpty( gradients ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { useBlockEditContext } from '../block-edit';
import useSetting from '../use-setting';
import { store as blockEditorStore } from '../../store';
import { __experimentalGetHighestPriorityPreset } from '../../utils';

const EMPTY_ARRAY = [];

Expand Down Expand Up @@ -68,10 +67,7 @@ export function __experimentalUseGradient( {
} = {} ) {
const { clientId } = useBlockEditContext();

const gradients =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
) || EMPTY_ARRAY;
const gradients = useSetting( 'color.gradients' ) || EMPTY_ARRAY;
const { gradient, customGradient } = useSelect(
( select ) => {
const { getBlockAttributes } = select( blockEditorStore );
Expand Down
10 changes: 3 additions & 7 deletions packages/block-editor/src/components/use-setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import { store as blockEditorStore } from '../../store';

const deprecatedFlags = {
'color.palette': ( settings ) =>
settings.colors === undefined ? undefined : { theme: settings.colors },
settings.colors === undefined ? undefined : settings.colors,
'color.gradients': ( settings ) =>
settings.gradients === undefined
? undefined
: { theme: settings.gradients },
settings.gradients === undefined ? undefined : settings.gradients,
'color.custom': ( settings ) =>
settings.disableCustomColors === undefined
? undefined
Expand All @@ -30,9 +28,7 @@ const deprecatedFlags = {
? undefined
: ! settings.disableCustomGradients,
'typography.fontSizes': ( settings ) =>
settings.fontSizes === undefined
? undefined
: { theme: settings.fontSizes },
settings.fontSizes === undefined ? undefined : settings.fontSizes,
'typography.customFontSize': ( settings ) =>
settings.disableCustomFontSizes === undefined
? undefined
Expand Down
11 changes: 2 additions & 9 deletions packages/block-editor/src/hooks/border-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import useSetting from '../components/use-setting';
import { hasBorderSupport, shouldSkipSerialization } from './border';
import { cleanEmptyObject } from './utils';
import { __experimentalGetHighestPriorityPreset } from '../utils';

// Defining empty array here instead of inline avoids unnecessary re-renders of
// color control.
Expand All @@ -45,10 +44,7 @@ export function BorderColorEdit( props ) {
attributes: { borderColor, style },
setAttributes,
} = props;
const colors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || EMPTY_ARRAY;
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const disableCustomColors = ! useSetting( 'color.custom' );
const disableCustomGradients = ! useSetting( 'color.customGradient' );

Expand Down Expand Up @@ -184,10 +180,7 @@ export const withBorderColorPaletteStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { name, attributes } = props;
const { borderColor } = attributes;
const colors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || EMPTY_ARRAY;
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;

if (
! hasBorderSupport( name, 'color' ) ||
Expand Down
16 changes: 3 additions & 13 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import { cleanEmptyObject } from './utils';
import ColorPanel from './color-panel';
import useSetting from '../components/use-setting';
import { __experimentalGetHighestPriorityPreset } from '../utils';

export const COLOR_SUPPORT_KEY = 'color';
const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -220,14 +219,8 @@ function immutableSet( object, path, value ) {
export function ColorEdit( props ) {
const { name: blockName, attributes } = props;
const isLinkColorEnabled = useSetting( 'color.link' );
const colors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || EMPTY_ARRAY;
const gradients =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.gradients' )
) || EMPTY_ARRAY;
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
const gradients = useSetting( 'color.gradients' ) || EMPTY_ARRAY;

// Shouldn't be needed but right now the ColorGradientsPanel
// can trigger both onChangeColor and onChangeBackground
Expand Down Expand Up @@ -395,10 +388,7 @@ export const withColorPaletteStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { name, attributes } = props;
const { backgroundColor, textColor } = attributes;
const colors =
__experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
) || EMPTY_ARRAY;
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
if ( ! hasColorSupport( name ) || shouldSkipSerialization( name ) ) {
return <BlockListBlock { ...props } />;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
__experimentalDuotoneControl as DuotoneControl,
useSetting,
} from '../components';
import { __experimentalGetHighestPriorityPreset } from '../utils';

/**
* Convert a list of colors to an object of R, G, and B values.
Expand Down Expand Up @@ -125,9 +124,7 @@ function DuotonePanel( { attributes, setAttributes } ) {
const duotone = style?.color?.duotone;

const duotonePalette = useSetting( 'color.duotone' );
const colorPalette = __experimentalGetHighestPriorityPreset(
useSetting( 'color.palette' )
);
const colorPalette = useSetting( 'color.palette' );
const disableCustomColors = ! useSetting( 'color.custom' );

return (
Expand Down
8 changes: 2 additions & 6 deletions packages/block-editor/src/hooks/font-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { hasBlockSupport } from '@wordpress/blocks';
import { cleanEmptyObject } from './utils';
import useSetting from '../components/use-setting';
import FontFamilyControl from '../components/font-family';
import { __experimentalGetHighestPriorityPreset } from '../utils';

export const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';

Expand All @@ -36,13 +35,12 @@ export function FontFamilyEdit( {
setAttributes,
attributes: { style = {} },
} ) {
let fontFamilies = useSetting( 'typography.fontFamilies' );
const fontFamilies = useSetting( 'typography.fontFamilies' );
const isDisable = useIsFontFamilyDisabled( { name } );

if ( isDisable ) {
return null;
}
fontFamilies = __experimentalGetHighestPriorityPreset( fontFamilies );

const value = getFontFamilyFromAttributeValue(
fontFamilies,
Expand Down Expand Up @@ -84,9 +82,7 @@ export function FontFamilyEdit( {
* @return {boolean} Whether setting is disabled.
*/
export function useIsFontFamilyDisabled( { name } ) {
const fontFamilies = __experimentalGetHighestPriorityPreset(
useSetting( 'typography.fontFamilies' )
);
const fontFamilies = useSetting( 'typography.fontFamilies' );
return (
! fontFamilies ||
fontFamilies.length === 0 ||
Expand Down
Loading

0 comments on commit d3cdc67

Please sign in to comment.