Skip to content

Commit

Permalink
Add support for cover block
Browse files Browse the repository at this point in the history
  • Loading branch information
roborourke committed Sep 2, 2024
1 parent 7d4f415 commit 94cd088
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build/editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'ec1f92331e23bb3e3019');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'be1b0e10cedb4cf08887');
17 changes: 9 additions & 8 deletions build/editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/editor.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/lottie-rtl.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*!********************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/lottie.css ***!
\********************************************************************************************************************************************************************/
.wp-block-image[data-lottie] {
[data-lottie] {
position: relative;
}

.wp-block-image.lottie-img-hidden img {
[data-lottie].lottie-img-hidden img {
visibility: hidden;
}

.wp-block-image[data-lottie] canvas {
[data-lottie] canvas {
position: absolute;
inset: 0 0 0 0;
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion build/lottie.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'dd653a7ad1d91f405479');
<?php return array('dependencies' => array(), 'version' => '05a3013820b1f18ac059');
6 changes: 3 additions & 3 deletions build/lottie.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/lottie.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions build/lottie.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/lottie.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lottie-lite.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* @param array $block The parsed block.
* @return string The block content.
*/
add_filter( 'render_block_core/image', function( string $block_content, array $block ) : string {
add_filter( 'render_block', function( string $block_content, array $block ) : string {
if ( empty( $block['attrs']['lottie'] ) ) {
return $block_content;
}
Expand Down
14 changes: 8 additions & 6 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import LottieLogo from '../assets/lottie-logo.png';

import './editor.css';

const SUPPORTED_BLOCKS = [ 'core/image', 'core/cover' ];

function useLottie( args = {} ) {
const dotLottie = useRef( null );
const ref = useCallback(
Expand Down Expand Up @@ -66,7 +68,7 @@ function LottieAnimationPanel( BlockEdit ) {
return ( props ) => {
const { attributes, name, setAttributes } = props;

if ( name !== 'core/image' ) {
if ( SUPPORTED_BLOCKS.indexOf( name ) < 0 ) {
return <BlockEdit { ...props } />;
}

Expand All @@ -88,11 +90,11 @@ function LottieAnimationPanel( BlockEdit ) {
>
<SelectControl
label={ __( 'Interaction', 'lottie-lite' ) }
value={ lottie?.trigger || 'none' }
value={ lottie?.trigger || '' }
options={ [
{
label: __( 'Autoplay', 'lottie-lite' ),
value: 'none',
value: '',
},
{
label: __( 'Hover', 'lottie-lite' ),
Expand Down Expand Up @@ -282,7 +284,7 @@ addFilter(
);

function addAttribute( settings ) {
if ( settings.name !== 'core/image' ) {
if ( SUPPORTED_BLOCKS.indexOf( settings.name ) < 0 ) {
return settings;
}

Expand Down Expand Up @@ -317,8 +319,8 @@ function addAttribute( settings ) {
},
trigger: {
type: 'string',
enum: [ 'none', 'click', 'hover' ],
default: 'none',
enum: [ '', 'click', 'hover' ],
default: '',
},
overlay: {
type: 'bool',
Expand Down
6 changes: 3 additions & 3 deletions src/lottie.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.wp-block-image[data-lottie] {
[data-lottie] {
position: relative;
}

.wp-block-image.lottie-img-hidden img {
[data-lottie].lottie-img-hidden img {
visibility: hidden;
}

.wp-block-image[data-lottie] canvas {
[data-lottie] canvas {
position: absolute;
inset: 0 0 0 0;
width: 100%;
Expand Down
5 changes: 3 additions & 2 deletions src/lottie.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ document.querySelectorAll( '[data-lottie]' ).forEach( ( lottie ) => {
canvas.style.width =
img?.width || img?.getBoundingClientRect().width || '100%';
canvas.style.height =
img?.height || img?.getBoundingClientRect().height || '100%';
img?.height || img?.getBoundingClientRect().height || 'auto';
canvas.style.aspectRatio = `${ img.width } / ${ img.height }`;

// Append - ensure if a link is used the canvas is inside to pick up clickable area.
img.parentElement.appendChild( canvas );
Expand All @@ -28,7 +29,7 @@ document.querySelectorAll( '[data-lottie]' ).forEach( ( lottie ) => {

let playerConfig = {};

if ( config.trigger === 'none' ) {
if ( ! config.trigger ) {
playerConfig.autoplay = true;
playerConfig.loop = true;
}
Expand Down

0 comments on commit 94cd088

Please sign in to comment.