| 1 |
(function (blocks, editor, components, i18n, element) { |
| 2 |
var el = element.createElement; |
| 3 |
var Fragment = element.Fragment; |
| 4 |
var __ = i18n.__; |
| 5 |
var InspectorControls = editor.InspectorControls; |
| 6 |
var useBlockProps = editor.useBlockProps; |
| 7 |
var PanelBody = components.PanelBody; |
| 8 |
var TextControl = components.TextControl; |
| 9 |
var ToggleControl = components.ToggleControl; |
| 10 |
var SelectControl = components.SelectControl; |
| 11 |
|
| 12 |
blocks.registerBlockType('wpforo/forums', { |
| 13 |
title: __('wpForo Forums', 'wpforo'), |
| 14 |
icon: 'admin-comments', |
| 15 |
category: 'widgets', |
| 16 |
edit: function (props) { |
| 17 |
var attributes = props.attributes; |
| 18 |
var setAttributes = props.setAttributes; |
| 19 |
var blockProps = useBlockProps(); |
| 20 |
|
| 21 |
var boards = window.wpforo_block_data ? window.wpforo_block_data.boards : []; |
| 22 |
var boardOptions = boards.map(function (board) { |
| 23 |
return { value: board.boardid, label: board.title }; |
| 24 |
}); |
| 25 |
|
| 26 |
return el(Fragment, null, |
| 27 |
el(InspectorControls, { key: 'inspector' }, |
| 28 |
el(PanelBody, { title: __('Settings', 'wpforo') }, |
| 29 |
el(TextControl, { |
| 30 |
label: __('Title', 'wpforo'), |
| 31 |
value: attributes.title, |
| 32 |
onChange: function (value) { |
| 33 |
setAttributes({ title: value }); |
| 34 |
}, |
| 35 |
}), |
| 36 |
el(SelectControl, { |
| 37 |
label: __('Board', 'wpforo'), |
| 38 |
value: attributes.boardid, |
| 39 |
options: boardOptions, |
| 40 |
onChange: function (value) { |
| 41 |
setAttributes({ boardid: parseInt(value) }); |
| 42 |
}, |
| 43 |
}), |
| 44 |
el(ToggleControl, { |
| 45 |
label: __('Display as dropdown', 'wpforo'), |
| 46 |
checked: attributes.dropdown, |
| 47 |
onChange: function (value) { |
| 48 |
setAttributes({ dropdown: value }); |
| 49 |
}, |
| 50 |
}), |
| 51 |
), |
| 52 |
), |
| 53 |
el('div', blockProps, |
| 54 |
el('div', { className: 'wpf-block-placeholder' }, |
| 55 |
el('span', { className: 'dashicons dashicons-admin-comments' }), |
| 56 |
__('wpForo Forums', 'wpforo'), |
| 57 |
), |
| 58 |
), |
| 59 |
); |
| 60 |
}, |
| 61 |
save: function () { |
| 62 |
return null; |
| 63 |
}, |
| 64 |
}); |
| 65 |
})( |
| 66 |
window.wp.blocks, |
| 67 |
window.wp.blockEditor, |
| 68 |
window.wp.components, |
| 69 |
window.wp.i18n, |
| 70 |
window.wp.element, |
| 71 |
); |
| 72 |
|