-
Notifications
You must be signed in to change notification settings - Fork 384
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
[WIP] Introduce amp-story support via Gutenberg blocks #1215
Closed
Closed
Changes from 19 commits
Commits
Show all changes
280 commits
Select commit
Hold shift + click to select a range
e5c84d0
Extend blocks to allow configuring the position in thirds template.
miina 88a05df
Merge develop & resolve conflicts.
miina 912439d
Merge branch 'amp-stories' into amp-story/layouts
miina 6ff0bf6
Add a partly working workaround for selectBlock issue.
miina ea4c776
Add background color for amp-story-page block.
miina 0929292
Adjust texts.
miina d6d3f69
Adjust texts.
miina b6f696a
Merge pull request #1380 from Automattic/amp-story/page-background
westonruter b486847
Merge amp-stories and resolve conflicts.
miina 5e9a535
Add animation controls for AMP Story layer blocks.
miina b7afb23
Ensure a singular AMP story always is_amp_endpoint
westonruter dc87187
Ensure amp-runtime and Gutenberg block styles are included on story t…
westonruter 6eca68b
Merge pull request #1347 from Automattic/amp-story/layouts
westonruter 8518dae
Merge amp-stories and resolve conflicts.
miina 10826df
Start adding animation for core blocks.
miina 6c569c8
Add animation to core blocks. Whitelist animation attributes.
miina 32b7524
Enable animations for CTA layer, too.
miina 4923569
Change animation settings source to attribute.
miina 15718e2
UI updates.
miina 224ef00
Revert "Whitelist animation attributes."
westonruter def0ce0
Merge branch 'develop' of https://github.com/Automattic/amp-wp into a…
westonruter e04df38
Merge pull request #1385 from Automattic/amp-story/layout-block
westonruter 9d3a103
Merge branch 'amp-stories' of https://github.com/Automattic/amp-wp in…
westonruter f70669b
Merge pull request #1388 from Automattic/amp-story/style_fixes
westonruter ce78023
Add icons to layer selection.
miina 924c22b
Fix jscs.
miina 4234619
Merge pull request #1391 from Automattic/amp-story/layout-icons
westonruter d056828
Add placeholder for animation duration according to the type.
miina 73d6b80
Merge pull request #1395 from Automattic/amp-story/animation-fix
westonruter 1ef3f8e
Merge remote-tracking branch 'origin/develop' into amp-stories
miina 6304f37
Merge branch 'amp-stories' of github.com:Automattic/amp-wp into amp-s…
miina 75feec6
Fix layer selection.
miina 2decbde
Merge pull request #1417 from Automattic/amp-story/layout-selection-fix
miina e69e44e
Disable amp-story post type when Gutenberg is not active.
miina 87c731a
Style fixes.
miina ed6393c
Increase z-index of a selected block.
miina b2df5c5
Hide resizer for amp-story images.
miina 25685d4
Add limits to resizing images.
miina 5884d6c
Merge pull request #1425 from Automattic/amp-story/fixes-vol1
westonruter 434282d
Use dotted outline instead of dotted border for selected blocks
westonruter cfd8e8d
Add opacity and background color controls for grid layer block.
miina 8ce58ce
Fix eslint issues.
miina 4b0606f
Merge pull request #1434 from Automattic/amp-story/grid-layer-background
westonruter 9a8158e
Change Opacity label to Layer Opacity.
miina 6415f6b
Style fix.
miina a865553
Improve image background styling.
miina 7690310
Modify importing 'uuid'.
miina 9dd04c9
Merge pull request #1504 from Automattic/fix/fix-uuid-package
miina 6bde3e2
Merge develop
miina a3c6c59
Change back uuid version.
miina d7788bf
Merge branch 'develop' into amp-stories
mehigh 7de1d76
Split Grid Layer block into 4 blocks based on template.
miina ca0f4ba
Add background fill layers.
miina 0a1b84c
Add background fill layers.
miina a285622
Fix margin for fill template.
miina fd654b9
Fix layer inserter.
miina 36e1f99
Remove AMP Story prefix from block names
jacobschweitzer 3910502
Add text domain to AMP stories block titles
jacobschweitzer 747be0d
Merge pull request #1595 from Automattic/amp-stories-remove-prefix
miina 95e14aa
Merge amp-stories & resolve conflicts.
miina ef637a6
Add text domains where missing.
miina 01a663d
Refactor code.
miina 10f334b
Refactor templating.
miina 9f4c5d0
Fix eslint.
miina 482676e
Merge remote-tracking branch 'origin/develop' into amp-stories
miina 6cd5978
Merge remote-tracking branch 'origin/amp-stories' into 1530-split_gri…
miina a9b25e8
Fix jshint. Again.
miina 3a458c3
Add placeholder SVG files for icons.
miina 69c47ea
Prepopulate new page with background image and vertical layer.
miina e9dcf0d
Fix eslint.
miina 05d1fd2
Merge remote-tracking branch 'origin/1530-split_grid_layer_block' int…
miina b5e0be4
Add correct SVG files.
miina 1456512
Merge pull request #1594 from Automattic/1530-split_grid_layer_block
miina 90f662a
Update creating warning notice.
miina 6f05668
Remove unused code.
miina c1e5f80
Merge remote-tracking branch 'origin/fix/displaying-validation-warnin…
miina 017b9cc
Add check for featured image in case of AMP Stories.
miina 8801bbd
1531 - Make ‘fill-image’ gray edit area full height
mehigh 786a0f3
Implement allowed_descendant_tags
miina 0758d00
Add check for existing child nodes.
miina 8ac21e1
1531 - Keep this full height when the contextual toolbar is present
mehigh 369d1ab
1531 - Avoid zooming the layers in on large screens
mehigh fa78eb9
1531 - Make image fill cover the layer entirely
mehigh 0502874
1531 - Limit max-height of the fill video to the size of the layer.
mehigh 89943fc
Add child_tags tags spec.
miina 9435205
Use remove_invalid_child instead of just removing the node.
miina f224c63
First try with reverting the amp-fit-text.
miina c5c9594
Add is-selected-parent class.
miina be0320a
Test commit.
miina ddd02d3
Merge remote-tracking branch 'origin/develop' into amp-stories
miina b8bc64a
Merge remote-tracking branch 'origin/amp-stories' into 1565-paragraph…
miina 1d7044b
Remove 'type' from attributes where source is set.
miina 6fe2a3f
Merge branch 'fix/block-attributes' into 1565-paragraph-font-adjustments
miina c42a1b2
Merge fixes for attributes.
miina 927bb57
1531 - Add animated opacity & blur change on selecting one of the layers
mehigh 7ec0969
Remove Layer cards.
miina 71cbcad
Adjust parsing ints.
miina f60ded5
Add custom block navigator.
miina 60e6543
1531 - Avoid zooming out the story on small height screens
mehigh a5fd75f
1531 - Removed unused variable
mehigh 1097760
1531 - Avoid overlap of blocks outlines inside of vertical
mehigh c46aa64
1531 - spaced out the blocks even more
mehigh aa3fcf0
1531 - Avoid images from shrinking on small height screens
mehigh 77949e3
1531 - Add 30% opacity + blur when selecting a layer with other layer…
mehigh b3c437b
1524 - Added blue border around rich text entries + white shadow
mehigh 97428ec
Add back is-selected-parent class.
miina 3b8c596
Merge branch '1531-prepopulate_page' of github.com:Automattic/amp-wp …
miina 086a9b3
Use data-amp-selected=parent istead of overwriting default classes.
miina ff909fa
Fix spacing.
miina 0debd1a
Merge branch 'amp-stories' into 1531-prepopulate_page
mehigh 63b4a0b
Merge pull request #1600 from Automattic/1531-prepopulate_page
mehigh 57fa077
Create custom block navigator to display nex to each page.
miina 34d7510
Replace custom layer inerter with default Inserter.
miina 7c095c2
Merge amp-stories and resolve conflicts.
miina fbee984
Styles for inserter to become ghosted page
5c9d8f1
Add new svg page icon
25aeacb
Add post type class to keep inserter styles siloed
b585484
Remove top margin from inserter
2caa417
Merge branch 'amp-stories' into 1524-improve-outline
mehigh df52684
1524 - Maintain blue outline of the currently selected layer (vertica…
mehigh 7f293bf
1524 - Maintain blue border when selecting the story page
mehigh 58ad519
1524 - Add white shadow to placeholder text
mehigh ec5d2c8
Merge pull request #1625 from Automattic/1565-paragraph-font-adjustments
mehigh 0d2f643
Merge branch 'amp-stories' into 1524-improve-outline
mehigh ce31892
1524 - Fix issue with warning block not being clickable
mehigh 4fa9923
1562: Block insertion of cta layer in first amp story page
jacobschweitzer 4d7fabb
Include wp-editor and fix custom blocks in Gutenberg 4.5.1
miina a2bab22
Merge amp-stories.
miina c0ac4f3
Merge pull request #1635 from Automattic/amp-story/enqeueue-wp-editor
miina f966c72
Merge branch 'amp-stories' into amp-story/1562
jacobschweitzer 26776a7
Fix blurred element issue when selecting AMP CTA child
jacobschweitzer 3e90bd1
Do not try to add class if no element exists
jacobschweitzer 3e1aac7
Add RichText template with placeholder
jacobschweitzer 86c8209
Remove template as it gives error on new CTA creation
jacobschweitzer ac6d42a
Add breadcrumb to selected layer blocks.
miina 25bdbcb
Add missing key.
miina 1788538
1532 - Optimised SVG
mehigh fdd938e
1532 - Optimize page inserter SVG
mehigh 065284c
Merge branch 'amp-stories' into 1532-improve-page-block-flow
mehigh 3722fb2
Fix not needed blocks being displayed in Inserter.
miina eac4334
1532 - Apply the ghosted page only to the last added on the page
mehigh 6815d2a
1562: Use core/button as template
jacobschweitzer 5718f0b
1532 - Updated page icon in side navigator
mehigh befd00e
1562: Use else if to prevent error when trying to remove block twice
jacobschweitzer 399adad
1532 - Add shadow hover animation on the ghosted page
mehigh 33384da
1532 - Missed turning the text into shapes in the vector.
mehigh 0e40c83
Merge pull request #1632 from Automattic/1532-improve-page-block-flow
mehigh b1ec0e7
Merge branch 'amp-stories' into 1524-improve-outline
mehigh 9a19ab9
1524 - Added border around the stories to match the ghost page
mehigh c690bd8
1524 - Removed some old outlines.
mehigh 3f84e61
1524 - Made CTA layer not overflow when too much text is entered
mehigh c9805e7
1524 - Removing important width on block list layout. (was causing CT…
mehigh 5211097
Use data-amp-selected attribute to identify parent CTA layer
jacobschweitzer 540e921
1522 - Update the border & background of the page
mehigh 5765b9a
Merge pull request #1629 from Automattic/1524-improve-outline
mehigh ead8800
Merge pull request #1644 from Automattic/amp-story/1559-improve_addin…
mehigh 96aa5c6
1562: Update props instead of using block selector for AMP story cta …
jacobschweitzer 16bf325
Merge remote-tracking branch 'origin/amp-stories' into amp-story/1562
miina 4e2f114
1532 - Added support for the older G block-list-apender for ghost page
mehigh 68161de
Merge pull request #1648 from Automattic/amp-story/1532-page-add
mehigh 453441d
Add missing text domain.
miina 3d8c915
Merge branch 'amp-stories' into amp-story/1563-improve_selecting_layers
mehigh 22002eb
Merge branch 'amp-stories' into amp-story/1564-layer_manipulation
mehigh 703c0e5
1562: Only add data-amp-selected to CTA layer
jacobschweitzer b37d430
Merge branch 'amp-story/1562' of https://github.com/Automattic/amp-wp…
jacobschweitzer 4bb91d4
Merge branch 'amp-story/1563-improve_selecting_layers' into amp-story…
mehigh dae0bcb
Improve CTA style.
miina 81a7459
Add outline for CTA layer blocks, too.
miina 2349c4f
Merge pull request #1636 from Automattic/amp-story/1562
miina 331239f
Merge branch 'amp-stories' into amp-story/1563-improve_selecting_layers
mehigh e65d501
Merge branch 'amp-story/1563-improve_selecting_layers' into amp-story…
mehigh 627837c
AMP Story - CSS comments + Table of Contents
mehigh 48d11d1
1564 - Make the label stay visible while the layer is selected
mehigh 4e646a2
Merge amp-stories.
miina e7aca95
Remove importing lodash.
miina f562534
1563 - Hide the always visible block navigator on smaller screens
mehigh 756f969
Resolve conflicts.
miina ddd6c00
Merge branch 'amp-story/1563-improve_selecting_layers' into amp-story…
mehigh 9ceef5f
Merge develop & resolve conflicts.
miina 418ad0c
1563 - Allow the cta layer to grow vertically
mehigh b9225d2
Revert "1563 - Allow the cta layer to grow vertically"
mehigh f8efb5d
1563 - Avoid Block Navigation from overlapping content
mehigh 47db39d
1563 - Comment
mehigh c18aecb
1563 - Add Layer text next to block navigation
mehigh 6139b63
Merge branch 'amp-stories' into amp-story/1564-layer_manipulation
mehigh 69a9c63
Rework Block Navigation
miina 9593a59
1563 - Update selectors to match reworked model
mehigh bc9c96b
1563 - Yeah
mehigh 9a0daf6
1563 - Fix the positioning of the add overlay to not overlap sidebar
mehigh 8e8dfe5
Merge pull request #1642 from Automattic/amp-story/1564-layer_manipul…
mehigh 7710a4e
Merge amp-stories & resolve conflicts.
miina ccb1edf
1532 - Hide the CTA element button when adding on first page
mehigh 0292335
Merge pull request #1655 from Automattic/amp-story/1532-add-cta
miina 48f08b2
Merge remote-tracking branch 'origin/amp-stories' into 1569-compatibi…
miina 859d0b8
Update python script.
miina 36c806e
1567: Add Image Caption Toggle script and CSS
jacobschweitzer 9e0fc03
Merge remote-tracking branch 'origin/amp-stories' into amp-story/1567
jacobschweitzer f513190
1567: Remove comma to fix ESLint issue
jacobschweitzer a3fc484
Update logic to match the new generated tags structure.
miina a15f5c1
Do not add postre portrait if it was not found, to cause AMP Validati…
miina 53a6363
Remove todo note.
miina 762f534
1567: Merge caption toggle with story editor blocks and add updates f…
jacobschweitzer e0518f1
1567: Remove value since we don’t use it
jacobschweitzer 50f2b10
1567: Remove trailing comma
jacobschweitzer 9cb077d
1567: Do not show toggle setting for fill image
jacobschweitzer 3ad171d
1567: Move image caption setting to AMP story settings section
jacobschweitzer cd133a5
Merge remote-tracking branch 'origin/develop' into amp-stories
miina 0d6ef21
Merge remote-tracking branch 'origin/develop' into 1569-compatibility…
miina 3258a8b
Remove type from animation settings.
miina 7c5f450
Merge pull request #1671 from Automattic/fix/animation-settings
miina bad703e
Hide adder inside story page when block navigation is visible
mehigh 5b33f35
block navigation doesn’t move up & down depending on the presence of …
mehigh a51d395
1567: Move image caption to renamed getAmpStorySettings function
jacobschweitzer f6e4b6a
Merge pull request #1663 from Automattic/amp-story/1567
miina 48f66cc
1673 - Implement mover arrows staying visible on the selected element
mehigh bef5822
Merge pull request #1675 from Automattic/amp-story/1673-polish
mehigh f44f7ad
Fix setting types again.
miina db1b45a
Merge branch '1.0' into amp-stories
miina 4dae11a
Merge remote-tracking branch 'origin/amp-stories' into amp-story/refi…
miina c31f2e4
Merge remote-tracking branch 'origin/amp-stories' into 1569-compatibi…
miina c3a304a
Fix amp-accordion tests.
miina 6f9845d
Only test up to WP 5.0; omit trunk since in flux
westonruter 8c35525
Revert "Only test up to WP 5.0; omit trunk since in flux"
westonruter 21669e1
Fix tests which broke with Gutenberg 4.6
westonruter 6348fdd
Merge pull request #1678 from Automattic/amp-story/refix_setting_types
westonruter 5f34291
Merge remote-tracking branch 'origin/develop' into amp-stories
miina f9da69f
Merge remote-tracking branch 'origin/amp-stories' into 1569-compatibi…
miina 8bda373
Update selector for image block.
miina 117c70a
Merge pull request #1690 from Automattic/1688-issues_with_animation
miina 56b6a96
Rework filtering wrapper properties.
miina 4b32fa7
Add temporary fix for displaying Add Layer inserter.
miina b3d1b50
Merge pull request #1702 from Automattic/amp-story/1696-fix_blurring_…
miina 8189af2
Fix wrapper filter.
miina b965172
Merge pull request #1706 from Automattic/amp-story/fix-wrapper-filter
miina 2adac6f
1643: Add font family option and frontend CSS
jacobschweitzer 1f04ada
1643: Enqueue CSS in admin to show font changes
jacobschweitzer 6d6668d
Merge remote-tracking branch 'AMPProject/develop' into amp-story/1643
jacobschweitzer 2397f02
1643: Add data-font-family attribute in editor
jacobschweitzer 813f4f9
1643: Fix translation function call for WP 5.0
jacobschweitzer bd24ab8
1643: Make function static
jacobschweitzer 844dab2
Fix CS issues.
miina f49b41b
Merge remote-tracking branch 'origin/develop' into amp-stories
miina 32de042
Merge remote-tracking branch 'origin/amp-stories' into amp-story/1643
miina f9e5fd8
Add fonts only to text blocks.
miina 70f0d83
Merge pull request #1713 from ampproject/amp-story/1643
miina 9fb5e20
Merge branch 'develop' of github.com:ampproject/amp-wp into amp-stories
westonruter 0dc42bd
Fix phpcs complaints re: NotInFooter and MultipleArguments
westonruter 28f4cef
Merge branch 'amp-stories' into 1569-compatibility_issues
westonruter e7ee234
Merge pull request #1614 from ampproject/1569-compatibility_issues
westonruter 95507fa
Merge branch 'develop' of github.com:ampproject/amp-wp into amp-stories
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
.editor-block-list__layout { | ||
background-color: #ffdddd; | ||
} | ||
.editor-block-list__layout .editor-block-list__layout { | ||
background-color: white; | ||
} | ||
div[data-type="amp/amp-story-page"] { | ||
background-color: #ddffdd; | ||
} | ||
div[data-type="amp/amp-story-grid-layer"] { | ||
background-color: #ddddff; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
const { __ } = wp.i18n; | ||
const { | ||
registerBlockType | ||
} = wp.blocks; | ||
const { | ||
InnerBlocks | ||
} = wp.editor; | ||
const { | ||
Notice | ||
} = wp.components; | ||
const { Component } = wp.element; | ||
|
||
const { | ||
select, | ||
dispatch | ||
} = wp.data; | ||
const { | ||
moveBlockToPosition, | ||
removeBlock | ||
} = dispatch( 'core/editor' ); | ||
|
||
const { | ||
getBlock, | ||
getBlockRootClientId, | ||
getBlockOrder | ||
} = select( 'core/editor' ); | ||
|
||
const ALLOWED_BLOCKS = [ | ||
'core/button', | ||
'core/code', | ||
'core/embed', | ||
'core/image', | ||
'core/list', | ||
'core/paragraph', | ||
'core/preformatted', | ||
'core/pullquote', | ||
'core/quote', | ||
'core/table', | ||
'core/verse', | ||
'core/video' | ||
]; | ||
|
||
/** | ||
* Register block. | ||
*/ | ||
export default registerBlockType( | ||
'amp/amp-story-cta-layer', | ||
{ | ||
title: __( 'AMP Story CTA Layer' ), | ||
category: 'layout', | ||
icon: 'grid-view', | ||
parent: [ 'amp/amp-story-page' ], | ||
|
||
/* | ||
* <amp-story-cta-layer>: | ||
* mandatory_ancestor: "AMP-STORY-PAGE" | ||
* descendant_tag_list: "amp-story-cta-layer-allowed-descendants" | ||
* | ||
* https://github.com/ampproject/amphtml/blob/87fe1d02f902be97b596b36ec3421592c83d241e/extensions/amp-story/validator-amp-story.protoascii#L172-L188 | ||
*/ | ||
|
||
edit: class extends Component { | ||
constructor( props ) { | ||
super( ...arguments ); | ||
this.props = props; | ||
this.props.attributes.hasMultipleCtaBlocks = this.hasMoreThanOneCtaBlock(); | ||
} | ||
|
||
shouldComponentUpdate() { | ||
if ( ! this.props.attributes.hasMultipleCtaBlocks ) { | ||
this.ensureBeingLastBlock(); | ||
} | ||
return true; | ||
} | ||
|
||
componentDidMount() { | ||
if ( this.props.attributes.hasMultipleCtaBlocks ) { | ||
removeBlock( this.props.clientId ); | ||
dispatch( 'core/editor' ).createWarningNotice( __( 'Multiple CTA Layers are not allowed, the block was removed.', 'amp' ) ); | ||
} | ||
} | ||
|
||
ensureBeingLastBlock() { | ||
// @todo Display notice if the block gets moved. | ||
const rootClientID = getBlockRootClientId( this.props.clientId ); | ||
const order = getBlockOrder( rootClientID ); | ||
|
||
// If the CTA is not the last block, move it there. | ||
if ( _.last( order ) !== this.props.clientId ) { | ||
moveBlockToPosition( this.props.clientId, rootClientID, rootClientID, this.props.attributes.layout, order.length - 1 ); | ||
} | ||
} | ||
|
||
render() { | ||
// In case of successful block removal this won't be visible. | ||
if ( this.props.attributes.hasMultipleCtaBlocks ) { | ||
return ( | ||
<Notice status="error" isDismissible={ false }>{ __( 'Multiple CTA Layers are not allowed. Please remove all but one.', 'amp' ) }</Notice> | ||
); | ||
} | ||
return ( | ||
<InnerBlocks key='contents' allowedBlocks={ ALLOWED_BLOCKS } /> | ||
); | ||
} | ||
|
||
hasMoreThanOneCtaBlock() { | ||
const parentBlock = getBlock( getBlockRootClientId( this.props.clientId ) ); | ||
if ( ! parentBlock ) { | ||
return false; | ||
} | ||
let ctaBlocks = 0; | ||
_.each( parentBlock.innerBlocks, function( child ) { | ||
if ( 'amp/amp-story-cta-layer' === child.name ) { | ||
ctaBlocks++; | ||
} | ||
} ); | ||
return 1 < ctaBlocks; | ||
} | ||
}, | ||
|
||
save( { attributes } ) { | ||
return ( | ||
<amp-story-cta-layer template={ attributes.template }> | ||
<InnerBlocks.Content /> | ||
</amp-story-cta-layer> | ||
); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const { __ } = wp.i18n; | ||
const { | ||
registerBlockType | ||
} = wp.blocks; | ||
const { | ||
InspectorControls, | ||
InnerBlocks | ||
} = wp.editor; | ||
const { | ||
SelectControl | ||
} = wp.components; | ||
|
||
const ALLOWED_BLOCKS = [ | ||
'core/code', | ||
'core/embed', | ||
'core/image', | ||
'core/list', | ||
'core/paragraph', | ||
'core/preformatted', | ||
'core/pullquote', | ||
'core/quote', | ||
'core/table', | ||
'core/verse', | ||
'core/video' | ||
]; | ||
|
||
function setBlockParent( props ) { | ||
if ( ALLOWED_BLOCKS.includes( props.name ) ) { | ||
return Object.assign( | ||
{}, | ||
props, | ||
{ parent: [ 'amp/amp-story-grid-layer' ] } | ||
); | ||
} | ||
return props; | ||
} | ||
|
||
wp.hooks.addFilter( | ||
'blocks.registerBlockType', | ||
'amp/set-block-parents', | ||
setBlockParent | ||
); | ||
|
||
/** | ||
* Register block. | ||
*/ | ||
export default registerBlockType( | ||
'amp/amp-story-grid-layer', | ||
{ | ||
title: __( 'AMP Story Grid Layer' ), | ||
category: 'layout', | ||
icon: 'grid-view', | ||
|
||
parent: [ 'amp/amp-story-page' ], | ||
attributes: { | ||
template: { | ||
type: 'string', | ||
source: 'attribute', | ||
selector: 'amp-story-grid-layer', | ||
attribute: 'template', | ||
default: 'fill' | ||
} | ||
}, | ||
|
||
/* | ||
* <amp-story-grid-layer>: | ||
* mandatory_ancestor: "AMP-STORY-PAGE" | ||
* descendant_tag_list: "amp-story-grid-layer-allowed-descendants" | ||
* | ||
* https://github.com/ampproject/amphtml/blob/87fe1d02f902be97b596b36ec3421592c83d241e/extensions/amp-story/validator-amp-story.protoascii#L172-L188 | ||
*/ | ||
|
||
edit( props ) { | ||
const { setAttributes } = props; | ||
return [ | ||
<InspectorControls key='inspector'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
<SelectControl | ||
key="template" | ||
label={ __( 'Template', 'amp' ) } | ||
value={ props.attributes.template } | ||
options={ [ | ||
{ | ||
value: 'fill', | ||
label: __( 'Fill', 'amp' ) | ||
}, | ||
{ | ||
value: 'horizontal', | ||
label: __( 'Horizontal', 'amp' ) | ||
}, | ||
{ | ||
value: 'thirds', | ||
label: __( 'Thirds', 'amp' ) | ||
}, | ||
{ | ||
value: 'vertical', | ||
label: __( 'Vertical', 'amp' ) | ||
} | ||
] } | ||
onChange={ value => ( setAttributes( { template: value } ) ) } | ||
/> | ||
</InspectorControls>, | ||
<InnerBlocks key='contents' allowedBlocks={ ALLOWED_BLOCKS } /> | ||
]; | ||
}, | ||
|
||
save( { attributes } ) { | ||
return ( | ||
<amp-story-grid-layer template={ attributes.template }> | ||
<InnerBlocks.Content /> | ||
</amp-story-grid-layer> | ||
); | ||
} | ||
} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
button
from the list since according to the specs it seems that the grid layer does not allow buttons/links, only the CTA layer does.