| 1 |
import { registerBlockType } from "@wordpress/blocks"; |
| 2 |
import generateBlockCSS from "../shared/generateBlockCSS"; |
| 3 |
import { isBlockEnabled } from "../../utils"; |
| 4 |
import { ContainerBlockIcon, ContainerPreviewImage } from "./icons"; |
| 5 |
import ContainerEdit from "./edit"; |
| 6 |
import ContainerSave from "./save"; |
| 7 |
|
| 8 |
const options = { |
| 9 |
apiVersion: 3, |
| 10 |
icon: ContainerBlockIcon, |
| 11 |
category: "sp-smart-post-show", |
| 12 |
name: "sp-smart-post-show/container", |
| 13 |
title: "Container", |
| 14 |
description: "Create beautiful layouts with a flexbox-powered container block.", |
| 15 |
// supports: { |
| 16 |
// align: ["wide", "full"], |
| 17 |
// }, |
| 18 |
example: { |
| 19 |
attributes: { |
| 20 |
isPreview: true, |
| 21 |
}, |
| 22 |
}, |
| 23 |
edit: (props) => (props.attributes.isPreview ? <ContainerPreviewImage /> : <ContainerEdit {...props} />), |
| 24 |
save: ContainerSave, |
| 25 |
generateCSS: (attributes) => generateBlockCSS(attributes, "sp-smart-post-show/container", "frontend"), |
| 26 |
deprecated: [ |
| 27 |
{ |
| 28 |
attributes: { |
| 29 |
columns: { |
| 30 |
type: "number", |
| 31 |
default: 3, |
| 32 |
}, |
| 33 |
}, |
| 34 |
|
| 35 |
// THIS DOES THE MIGRATION |
| 36 |
migrate: ( attributes ) => { |
| 37 |
return { |
| 38 |
...attributes, |
| 39 |
columns: { |
| 40 |
Desktop: attributes.columns ?? 3, |
| 41 |
Tablet: 2, |
| 42 |
Mobile: 1, |
| 43 |
}, |
| 44 |
}; |
| 45 |
}, |
| 46 |
}, |
| 47 |
], |
| 48 |
}; |
| 49 |
|
| 50 |
const registerBlockTypeFn = () => { |
| 51 |
if (isBlockEnabled(options.name)) { |
| 52 |
registerBlockType(options.name, options); |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
registerBlockTypeFn(); |
| 57 |
|