sab_gutenberg_editor_script.js
75 lines
| 1 | import Edit from './components/edit'; |
| 2 | |
| 3 | import icons from './utils/icons'; |
| 4 | |
| 5 | const { registerBlockType } = wp.blocks; |
| 6 | |
| 7 | |
| 8 | class SAB_Gutenberg { |
| 9 | |
| 10 | constructor() { |
| 11 | this.registerBlock(); |
| 12 | } |
| 13 | |
| 14 | registerBlock() { |
| 15 | |
| 16 | /** |
| 17 | * Block attributes |
| 18 | */ |
| 19 | const blockAttributes = { |
| 20 | authorID: { |
| 21 | type: 'integer', |
| 22 | default: 0, |
| 23 | }, |
| 24 | display_name: { |
| 25 | type: 'string', |
| 26 | default: '', |
| 27 | }, |
| 28 | avatar: { |
| 29 | type: 'string', |
| 30 | default: '', |
| 31 | }, |
| 32 | profile_image: { |
| 33 | type: 'string', |
| 34 | default: '', |
| 35 | }, |
| 36 | description: { |
| 37 | type: 'string', |
| 38 | default: '', |
| 39 | }, |
| 40 | user_url: { |
| 41 | type: 'string', |
| 42 | default: '', |
| 43 | }, |
| 44 | social_links: { |
| 45 | type: 'array', |
| 46 | default: '', |
| 47 | }, |
| 48 | status: { |
| 49 | type: 'string', |
| 50 | default: 'loading', |
| 51 | }, |
| 52 | }; |
| 53 | |
| 54 | registerBlockType( 'simple-author-box/sab', { |
| 55 | title: 'Simple Author Box', |
| 56 | icon: icons.author, |
| 57 | category: 'common', |
| 58 | supports: { |
| 59 | customClassName: false, |
| 60 | }, |
| 61 | attributes: blockAttributes, |
| 62 | edit: Edit, |
| 63 | save() { |
| 64 | // Rendering in PHP |
| 65 | return null; |
| 66 | }, |
| 67 | } ); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | |
| 72 | } |
| 73 | |
| 74 | window.sab = new SAB_Gutenberg(); |
| 75 |