PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / MultiFormGoals / resources / js / blocks / multi-form-goal / edit / index.js

index.js in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/MultiFormGoals/resources/js/blocks/multi-form-goal/edit/index.js

58 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import {__} from '@wordpress/i18n';
5
6 const {InnerBlocks} = wp.blockEditor;
7 const {useEffect} = wp.element;
8 const {select, dispatch} = wp.data;
9
10 const edit = ({isSelected, clientId}) => {
11 // When adding a new Multi-Form Goal block, select the inner Progress Bar block by default
12 useEffect(() => {
13 if (isSelected) {
14 selectProgressBar();
15 }
16 }, []);
17
18 const selectProgressBar = () => {
19 const parentBlock = select('core/editor').getBlocksByClientId(clientId)[0];
20 const progressBarBlock = parentBlock.innerBlocks[parentBlock.innerBlocks.length - 1];
21 // prevent error if progressBarBlock is slow to load
22 if (progressBarBlock) {
23 dispatch('core/block-editor').selectBlock(progressBarBlock.clientId);
24 }
25 };
26
27 const blockTemplate = [
28 [
29 'core/media-text',
30 {
31 imageFill: true,
32 },
33 [
34 [
35 'core/heading',
36 {
37 placeholder: __('Heading', 'give'),
38 },
39 ],
40 [
41 'core/paragraph',
42 {
43 placeholder: __('Summary', 'give'),
44 },
45 ],
46 ],
47 ],
48 ['give/progress-bar', {}],
49 ];
50
51 return (
52 <div className="give-multi-form-goal-block">
53 <InnerBlocks template={blockTemplate} templateLock="all" />
54 </div>
55 );
56 };
57 export default edit;
58