Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
14b57c7
Fix: Gallery Block: Append images alt in aria-label attribute.
donmhico Aug 20, 2019
e5e571e
Fix: InnerBlocks template sync only on direct locked all (#16973)
jorgefilipecosta Aug 20, 2019
ca4c21c
Check to ensure focus has intentionally left the wrapped component in…
getdave Aug 20, 2019
c413f03
Fix: Required block appender styles are set on edit post (#16943)
jorgefilipecosta Aug 20, 2019
32819b8
Document server functions in block style variations section (#16997)
jorgefilipecosta Aug 20, 2019
3bcf6aa
[RNMobile] update mobile to not use ListEdit (#17070)
mchowning Aug 20, 2019
91b9104
Typewriter experience (#16460)
ellatrix Aug 20, 2019
af23ee6
[RNMobile] Hide replaceable block when adding block (#16931)
mchowning Aug 20, 2019
a2688c0
Update video player style on mobile
maxme Jul 25, 2019
3b74d9c
Add: Disabled block count in the block manager (#17103)
jorgefilipecosta Aug 21, 2019
1b05159
Use `400` as a valid `font-weight`
ntwb Aug 15, 2019
ac95cf6
Writing Flow/Quote: allow splitting (#17121)
ellatrix Aug 21, 2019
a2d0609
Build: remove global install of latest npm since we want to use the p…
gwwar Aug 22, 2019
b89271b
Project automation: Rewrite actions using JavaScript (#17080)
noisysocks Aug 22, 2019
b77291b
Writing Flow: allow undo of patterns with BACKSPACE and ESC (#14776)
ellatrix Aug 22, 2019
e832a89
Apply box-sizing border-box properly to the notices components (#17066)
youknowriad Aug 22, 2019
6146930
Fix: Converting an image using an external source to a gallery does n…
jorgefilipecosta Aug 22, 2019
ccea4f2
Editor: Update the store to use Core Data entities. (#16932)
epiqueras Aug 22, 2019
be881a3
Add callbacks to ServerSideRenderer to handle failures with custom re…
mikejolley Aug 22, 2019
393e01e
[RNMobile] Insure tapping at end of post inserts at end
mchowning Aug 6, 2019
5d21cd0
Project management automation: Fix 'add first time contributor label'…
noisysocks Aug 23, 2019
05b173c
Scripts: Improve recommended settings included in the package (#17027)
gziolo Aug 23, 2019
3386f46
Project management automation: Fix 'add milestone' (#17157)
noisysocks Aug 23, 2019
b5a6978
chore: Remove unused css from ColorPalette component (#17152)
jorgefilipecosta Aug 23, 2019
e1ef1c9
Add the block example API and use it for inserter and switcher previe…
youknowriad Aug 23, 2019
555f726
Fix: Block toolbar appears above sidebar on medium viewports (#17108)
jorgefilipecosta Aug 23, 2019
1f6c3b4
eslint BaseControl fix for TypeError: Cannot read property 'name' of …
bfintal Aug 24, 2019
253eaa3
Docs: Fix creating-dynamic-blocks typo (#17172)
jrchamp Aug 24, 2019
1011b19
remove selection toggle on image (#17175)
senadir Aug 25, 2019
42e2f0c
Add circle-crop variation to Image block. (#16475)
Aug 25, 2019
a356b79
Add: Option to select the style that is automatically applied (#16465)
jorgefilipecosta Aug 26, 2019
c2188c0
Enable an optional namespace parameter for hasAction & hasFilter (#15…
adamsilverstein Aug 26, 2019
190de96
Add get_item_schema function to WP_REST_Widget_Areas_Controller (#15981)
jorgefilipecosta Aug 26, 2019
666cbd7
fix(scripts): Use the SCSS shared stylelint-config-wordpress config (…
ntwb Aug 26, 2019
5319aea
Add option to resize Cover Block (#17143)
senadir Aug 26, 2019
539ec35
Fix: Empty Classic Editor inside innerBlock fatal error (#17164)
donmhico Aug 26, 2019
d562340
Allow directly setting a background to Cover (#17041)
senadir Aug 26, 2019
a0d228b
Bump plugin version to 6.4.0-rc.1
jorgefilipecosta Aug 26, 2019
422d812
Update the post schedule label to correctly reflect the date and (#15…
brentswisher Aug 26, 2019
503a804
Use the image alt logic in image block to determine the aria-labels i…
donmhico Aug 27, 2019
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
Prev Previous commit
Next Next commit
Add: Option to select the style that is automatically applied (#16465)
Squashed commits:
[ffd16b5] Add unit tests
[51dd9dc] Refactor & changed the design
[3b9ac24] Add: Option to allow user to select the style that is automatically applied.
  • Loading branch information
jorgefilipecosta authored and donmhico committed Aug 27, 2019
commit a356b790f2a8557aec40c325c463124eb42bbd07
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,17 @@ _Returns_

- `Object`: Action object

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

Returns an action object used in signaling that a style should be auto-applied when a block is created.

_Parameters_

- _blockName_ `string`: Name of the block.
- _blockStyle_ `?string`: Name of the style that should be auto applied. If undefined, the "auto apply" setting of the block is removed.

_Returns_

- `Object`: Action object.

<!-- END TOKEN(Autogenerated actions) -->
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import InspectorControls from '../inspector-controls';
import InspectorAdvancedControls from '../inspector-advanced-controls';
import BlockStyles from '../block-styles';
import MultiSelectionInspector from '../multi-selection-inspector';
import DefaultStylePicker from '../default-style-picker';
const BlockInspector = ( {
blockType,
count,
Expand Down Expand Up @@ -61,6 +62,7 @@ const BlockInspector = ( {
<BlockStyles
clientId={ selectedBlockClientId }
/>
<DefaultStylePicker blockName={ blockType.name } />
</PanelBody>
</div>
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { useMemo, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { SelectControl } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

export default function DefaultStylePicker( { blockName } ) {
const {
preferredStyle,
onUpdatePreferredStyleVariations,
styles,
} = useSelect(
( select ) => {
const settings = select( 'core/block-editor' ).getSettings();
const preferredStyleVariations = settings.__experimentalPreferredStyleVariations;
return {
preferredStyle: get(
preferredStyleVariations,
[ 'value', blockName ]
),
onUpdatePreferredStyleVariations: get(
preferredStyleVariations,
[ 'onChange' ],
null
),
styles: select( 'core/blocks' ).getBlockStyles( blockName ),
};
},
[ blockName ]
);
const selectOptions = useMemo(
() => ( [
{ label: __( 'Not set' ), value: '' },
...styles.map( ( { label, name } ) => ( { label, value: name } ) ),
] ),
[ styles ],
);
const selectOnChange = useCallback(
( blockStyle ) => {
onUpdatePreferredStyleVariations( blockName, blockStyle );
},
[ blockName, onUpdatePreferredStyleVariations ]
);

return onUpdatePreferredStyleVariations && (
<SelectControl
options={ selectOptions }
value={ preferredStyle || '' }
label={ __( 'Default Style' ) }
onChange={ selectOnChange }
/>
);
}
45 changes: 42 additions & 3 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { castArray, first } from 'lodash';
import { castArray, first, get, includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -218,6 +218,33 @@ export function toggleSelection( isSelectionEnabled = true ) {
};
}

function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
const preferredStyleVariations = get(
blockEditorSettings,
[ '__experimentalPreferredStyleVariations', 'value' ],
{}
);
return blocks.map( ( block ) => {
const blockName = block.name;
if ( ! preferredStyleVariations[ blockName ] ) {
return block;
}
const className = get( block, [ 'attributes', 'className' ] );
if ( includes( className, 'is-style-' ) ) {
return block;
}
const { attributes = {} } = block;
const blockStyle = preferredStyleVariations[ blockName ];
return {
...block,
attributes: {
...attributes,
className: `${ ( className || '' ) } is-style-${ blockStyle }`.trim(),
},
};
} );
}

/**
* Returns an action object signalling that a blocks should be replaced with
* one or more replacement blocks.
Expand All @@ -231,7 +258,13 @@ export function toggleSelection( isSelectionEnabled = true ) {
*/
export function* replaceBlocks( clientIds, blocks, indexToSelect ) {
clientIds = castArray( clientIds );
blocks = castArray( blocks );
blocks = getBlocksWithDefaultStylesApplied(
castArray( blocks ),
yield select(
'core/block-editor',
'getSettings',
)
);
const rootClientId = yield select(
'core/block-editor',
'getBlockRootClientId',
Expand Down Expand Up @@ -398,7 +431,13 @@ export function* insertBlocks(
rootClientId,
updateSelection = true
) {
blocks = castArray( blocks );
blocks = getBlocksWithDefaultStylesApplied(
castArray( blocks ),
yield select(
'core/block-editor',
'getSettings',
)
);
const allowedBlocks = [];
for ( const block of blocks ) {
const isValid = yield select(
Expand Down
Loading