PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.3
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.3
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / modules / quick-action-sidebar / components / blocks.js
sureforms / modules / quick-action-sidebar / components Last commit date
Modal.js 2 years ago Sidebar.js 2 years ago blocks.js 2 years ago draggable-block.js 2 years ago move-up-down.js 2 years ago
blocks.js
87 lines
1 /**
2 * Creates sidebar blocks.
3 */
4 import { useSelect } from '@wordpress/data';
5 import { createBlock, getBlockTypes } from '@wordpress/blocks';
6 import DraggableBlock from './draggable-block';
7 import DragAndDropComponent from './move-up-down';
8
9 const Blocks = ( {
10 defaultAllowedQuickSidebarBlocks,
11 updateDefaultAllowedQuickSidebarBlocks,
12 saveOptionToDatabase,
13 enableRearrange,
14 } ) => {
15 const blocks = getBlockTypes();
16 const {
17 blockInsertionPoint,
18 getBlockRootClientId,
19 getSelectedBlockAllowedBlocks,
20 getSelectedBlockClientId,
21 } = useSelect( ( select ) => {
22 const blockEditor = select( 'core/block-editor' );
23 const { index } = blockEditor.getBlockInsertionPoint();
24 const clientId = blockEditor.getSelectedBlockClientId();
25 const rootClientId = blockEditor.getBlockRootClientId(
26 getSelectedBlockClientId
27 );
28 const allowedBlocks = blockEditor.getAllowedBlocks( clientId );
29 return {
30 blockInsertionPoint: index,
31 getBlockRootClientId: rootClientId,
32 getSelectedBlockClientId: clientId,
33 getSelectedBlockAllowedBlocks: allowedBlocks || [],
34 };
35 } );
36 const srfmBlocks = blocks.filter( ( block ) => {
37 return defaultAllowedQuickSidebarBlocks.includes( block.name );
38 } );
39 const create = ( name ) => {
40 return createBlock( name );
41 };
42
43 // Loop through each object and add id
44 srfmBlocks.forEach( ( item, index ) => {
45 item.id = `${ index + 1 }`;
46 } );
47
48 const sortedY = defaultAllowedQuickSidebarBlocks
49 .filter( ( item ) => item !== undefined && item !== null )
50 .map( ( item ) => srfmBlocks.find( ( { name } ) => name === item ) )
51 .filter( ( item ) => item !== undefined ); // Remove undefined objects
52
53 return (
54 <>
55 { ! enableRearrange &&
56 sortedY.map( ( block, index ) => (
57 <DraggableBlock
58 key={ index }
59 id={ index }
60 { ...{
61 block,
62 create,
63 blockInsertionPoint,
64 getBlockRootClientId,
65 getSelectedBlockClientId,
66 getSelectedBlockAllowedBlocks,
67 defaultAllowedQuickSidebarBlocks,
68 updateDefaultAllowedQuickSidebarBlocks,
69 saveOptionToDatabase,
70 } }
71 />
72 ) ) }
73 { enableRearrange && (
74 <DragAndDropComponent
75 initialItems={ sortedY }
76 updateDefaultAllowedQuickSidebarBlocks={
77 updateDefaultAllowedQuickSidebarBlocks
78 }
79 saveOptionToDatabase={ saveOptionToDatabase }
80 />
81 ) }
82 </>
83 );
84 };
85
86 export default Blocks;
87