Skip to content

Commit

Permalink
add other deprecation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed Feb 28, 2024
1 parent 12dcc61 commit 1337d54
Show file tree
Hide file tree
Showing 46 changed files with 929 additions and 61 deletions.
8 changes: 7 additions & 1 deletion src/block/accordion/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const deprecated = [

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

return newAttributes
},
Expand All @@ -42,6 +44,8 @@ const deprecated = [

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
},
Expand All @@ -52,7 +56,9 @@ const deprecated = [
attributes: attributes( '3.7.9' ),
save: withVersion( '3.7.9' )( Save ),
migrate: attributes => {
const newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
let newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
return deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
},
},
Expand Down
14 changes: 12 additions & 2 deletions src/block/blockquote/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ const deprecated = [
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'

return hasBlockShadow || hasContainerShadow
return hasBlockShadow || hasContainerShadow || isNotV4
},
migrate: attributes => {
let newAttributes = { ...attributes }
let newAttributes = {
...attributes,
version: 2,
}

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

return newAttributes
},
Expand All @@ -44,6 +50,8 @@ const deprecated = [
version: 2,
}

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

Expand Down Expand Up @@ -85,6 +93,8 @@ const deprecated = [
}
}

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

Expand Down
8 changes: 7 additions & 1 deletion src/block/button-group/deprecated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const deprecated = [

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

return newAttributes
},
Expand All @@ -44,6 +46,8 @@ const deprecated = [

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
},
Expand All @@ -53,7 +57,9 @@ const deprecated = [
attributes: attributes( '3.7.9' ),
save: withVersion( '3.7.9' )( Save ),
migrate: attributes => {
const newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
let newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
return deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
},
},
Expand Down
11 changes: 10 additions & 1 deletion src/block/button/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const deprecated = [

newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'button%s' )( attributes )
newAttributes = deprecateShadowColor.migrate( 'button%s' )( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateButtonGradientColor.migrate( 'button%s' )( newAttributes )

return newAttributes
},
Expand All @@ -47,6 +50,9 @@ const deprecated = [
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateButtonGradientColor.migrate( 'button%s' )( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'button%s' )( newAttributes )

return newAttributes
},
Expand All @@ -58,6 +64,9 @@ const deprecated = [
migrate: attributes => {
let newAttributes = deprecateContainerBackgroundColorOpacity.migrate( attributes )
newAttributes = deprecateButtonGradientColor.migrate( 'button%s' )( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'button%s' )( newAttributes )
return deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
},
},
Expand Down
67 changes: 63 additions & 4 deletions src/block/call-to-action/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,69 @@ const deprecated = [
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const hasTopSeparatorShadow = deprecateShadowColor.isEligible( 'topSeparator%s' )( attributes )
const hasBottomSeparatorShadow = deprecateShadowColor.isEligible( 'bottomSeparator%s' )( attributes )
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'

return hasBlockShadow || hasContainerShadow || hasTopSeparatorShadow || hasBottomSeparatorShadow
return hasBlockShadow || hasContainerShadow || hasTopSeparatorShadow || hasBottomSeparatorShadow || isNotV4
},
migrate: attributes => {
let newAttributes = { ...attributes }
migrate: ( attributes, innerBlocks ) => {
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'

let newAttributes = {
...attributes,
}

if ( isNotV4 ) {
newAttributes = {
...newAttributes,
version: 2,
}

// Update the vertical align into flexbox
const hasOldVerticalAlign = !! attributes.containerVerticalAlign // Column only, this was changed to flexbox

if ( hasOldVerticalAlign ) {
newAttributes = {
...newAttributes,
containerVerticalAlign: '',
innerBlockAlign: attributes.containerVerticalAlign,
}
}

// If the inner blocks are horizontal, adjust to accomodate the new
// column gap, it will modify blocks because people used block
// margins before instead of a proper column gap.
if ( attributes.innerBlockOrientation === 'horizontal' ) {
innerBlocks.forEach( ( block, index ) => {
if ( index ) {
if ( ! block.attributes.blockMargin ) {
block.attributes.blockMargin = {
top: '',
right: '',
bottom: '',
left: '',
}
}
if ( block.attributes.blockMargin.left === '' ) {
block.attributes.blockMargin.left = 24
}
}
} )

newAttributes = {
...newAttributes,
innerBlockColumnGap: 0,
}
}
}

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )

return newAttributes
return [ newAttributes, innerBlocks ]
},
},
// Support the new combined opacity and color.
Expand Down Expand Up @@ -122,6 +173,10 @@ const deprecated = [

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )

return [ newAttributes, innerBlocks ]
},
Expand Down Expand Up @@ -200,6 +255,10 @@ const deprecated = [

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )

return [ newAttributes, innerBlocks ]
},
Expand Down
64 changes: 60 additions & 4 deletions src/block/card/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,68 @@ const deprecated = [
isEligible: attributes => {
const hasBlockShadow = deprecateBlockShadowColor.isEligible( attributes )
const hasContainerShadow = deprecateContainerShadowColor.isEligible( attributes )
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'

return hasBlockShadow || hasContainerShadow
return hasBlockShadow || hasContainerShadow || isNotV4
},
migrate: attributes => {
let newAttributes = { ...attributes }
migrate: ( attributes, innerBlocks ) => {
const isNotV4 = attributes.version < 2 || typeof attributes.version === 'undefined'

let newAttributes = {
...attributes,
}

if ( isNotV4 ) {
newAttributes = {
...newAttributes,
version: 2,
}

// Update the vertical align into flexbox
const hasOldVerticalAlign = !! attributes.containerVerticalAlign // Column only, this was changed to flexbox

if ( hasOldVerticalAlign ) {
newAttributes = {
...newAttributes,
containerVerticalAlign: '',
innerBlockAlign: attributes.containerVerticalAlign,
}
}

// If the inner blocks are horizontal, adjust to accomodate the new
// column gap, it will modify blocks because people used block
// margins before instead of a proper column gap.
if ( attributes.innerBlockOrientation === 'horizontal' ) {
innerBlocks.forEach( ( block, index ) => {
if ( index ) {
if ( ! block.attributes.blockMargin ) {
block.attributes.blockMargin = {
top: '',
right: '',
bottom: '',
left: '',
}
}
if ( block.attributes.blockMargin.left === '' ) {
block.attributes.blockMargin.left = 24
}
}
} )

newAttributes = {
...newAttributes,
innerBlockColumnGap: 0,
}
}
}

newAttributes = deprecationImageOverlayOpacity.migrate( newAttributes ),
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return newAttributes
return [ newAttributes, innerBlocks ]
},
},
{
Expand Down Expand Up @@ -170,6 +222,8 @@ const deprecated = [
newAttributes = deprecationImageOverlayOpacity.migrate( newAttributes ),
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return [ newAttributes, innerBlocks ]
},
Expand Down Expand Up @@ -249,6 +303,8 @@ const deprecated = [
newAttributes = deprecationImageOverlayOpacity.migrate( newAttributes ),
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )

return [ newAttributes, innerBlocks ]
},
Expand Down
6 changes: 6 additions & 0 deletions src/block/carousel/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const deprecated = [
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )
newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )

return newAttributes
},
Expand All @@ -46,6 +48,10 @@ const deprecated = [

newAttributes = deprecateContainerBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockBackgroundColorOpacity.migrate( newAttributes )
newAttributes = deprecateBlockShadowColor.migrate( newAttributes )
newAttributes = deprecateContainerShadowColor.migrate( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'topSeparator%s' )( newAttributes )
newAttributes = deprecateShadowColor.migrate( 'bottomSeparator%s' )( newAttributes )

return newAttributes
},
Expand Down
Loading

0 comments on commit 1337d54

Please sign in to comment.