components
1 year ago
css
3 years ago
attributes.js
2 years ago
block.js
1 year ago
deprecated.js
3 years ago
edit.js
2 years ago
editor.scss
4 years ago
transforms.js
1 year ago
block.js
65 lines
| 1 | /** |
| 2 | * Block: Grid |
| 3 | */ |
| 4 | |
| 5 | import './editor.scss'; |
| 6 | import editGridContainer from './edit'; |
| 7 | import blockAttributes from './attributes'; |
| 8 | import getIcon from '../../utils/get-icon'; |
| 9 | import deprecated from './deprecated'; |
| 10 | import { __ } from '@wordpress/i18n'; |
| 11 | import { registerBlockType } from '@wordpress/blocks'; |
| 12 | import { InnerBlocks } from '@wordpress/block-editor'; |
| 13 | import { getBlockAttributes } from '../../block-context'; |
| 14 | import gridContext from '../../block-context/grid'; |
| 15 | import { transforms } from './transforms'; |
| 16 | |
| 17 | const attributes = getBlockAttributes( |
| 18 | blockAttributes, |
| 19 | gridContext, |
| 20 | generateBlocksDefaults.gridContainer |
| 21 | ); |
| 22 | |
| 23 | /** |
| 24 | * Register our Grid block. |
| 25 | * |
| 26 | * @param {string} name Block name. |
| 27 | * @param {Object} settings Block settings. |
| 28 | * @return {?WPBlock} The block, if it has been successfully |
| 29 | * registered; otherwise `undefined`. |
| 30 | */ |
| 31 | registerBlockType( 'generateblocks/grid', { |
| 32 | apiVersion: 3, |
| 33 | title: __( 'Grid', 'generateblocks' ), |
| 34 | description: __( 'Create advanced layouts with flexible grids.', 'generateblocks' ), |
| 35 | icon: getIcon( 'grid' ), |
| 36 | category: 'generateblocks', |
| 37 | keywords: [ |
| 38 | __( 'grid' ), |
| 39 | __( 'column' ), |
| 40 | __( 'generate' ), |
| 41 | ], |
| 42 | attributes, |
| 43 | supports: { |
| 44 | className: false, |
| 45 | html: false, |
| 46 | }, |
| 47 | edit: editGridContainer, |
| 48 | save: () => { |
| 49 | return ( |
| 50 | <InnerBlocks.Content /> |
| 51 | ); |
| 52 | }, |
| 53 | deprecated, |
| 54 | __experimentalLabel: ( attrs, { context } ) => { |
| 55 | const customName = attrs?.metadata?.name || attrs?.blockLabel; |
| 56 | |
| 57 | if ( 'list-view' === context && customName ) { |
| 58 | return customName; |
| 59 | } |
| 60 | |
| 61 | return __( 'Grid', 'generateblocks' ); |
| 62 | }, |
| 63 | transforms, |
| 64 | } ); |
| 65 |