PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.2.0
GenerateBlocks v2.2.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / query / edit.js
generateblocks / src / blocks / query Last commit date
components 1 year ago block.json 1 year ago edit.js 1 year ago index.js 1 year ago looper.js 1 year ago query-parameters.js 1 year ago save.js 1 year ago templates.js 1 year ago toolbar-appenders.js 1 year ago
edit.js
140 lines
1 import { useBlockProps, InspectorControls, useInnerBlocksProps } from '@wordpress/block-editor';
2 import { useEffect, useMemo } from '@wordpress/element';
3 import { compose } from '@wordpress/compose';
4 import { __ } from '@wordpress/i18n';
5
6 import { BlockStyles, withUniqueId } from '@edge22/block-styles';
7
8 import RootElement from '../../components/root-element/index.js';
9 import { TemplateSelector } from '@components/template-selector';
10 import { TEMPLATES } from './templates';
11 import { BlockSettings } from './components/BlockSettings';
12 import { selectorShortcuts } from '@utils/selectorShortcuts';
13 import { withStyles } from '@hoc/withStyles';
14 import { BlockAppender, BlockStylesBuilder } from '@components/index';
15 import { withHtmlAttributes } from '@hoc/withHtmlAttributes.js';
16 import { getBlockClasses } from '@utils/getBlockClasses.js';
17
18 function EditBlock( props ) {
19 const {
20 attributes,
21 setAttributes,
22 name,
23 clientId,
24 onStyleChange,
25 editorHtmlAttributes,
26 styles,
27 isSelected,
28 } = props;
29
30 const {
31 tagName,
32 showTemplateSelector,
33 } = attributes;
34
35 const classNames = getBlockClasses(
36 'gb-query',
37 {
38 ...attributes,
39 styles,
40 }
41 );
42
43 useEffect( () => {
44 if ( ! tagName ) {
45 setAttributes( { tagName: 'div' } );
46 }
47 }, [ tagName ] );
48
49 const blockProps = useBlockProps(
50 {
51 className: classNames.join( ' ' ).trim(),
52 ...editorHtmlAttributes,
53 }
54 );
55
56 const innerBlocksProps = useInnerBlocksProps(
57 blockProps,
58 {
59 allowedBlocks: [
60 'generateblocks/looper',
61 'generateblocks/query-no-results',
62 'generateblocks/query-page-numbers',
63 'generateblocks/element',
64 ],
65 renderAppender: () => (
66 <BlockAppender
67 clientId={ clientId }
68 isSelected={ isSelected }
69 attributes={ attributes }
70 />
71 ),
72 }
73 );
74
75 const TagName = tagName || 'div';
76 const shortcuts = useMemo( () => {
77 const visibleShortcuts = [
78 {
79 label: __( 'Links', 'generateblocks' ),
80 value: 'a',
81 },
82 ];
83
84 return {
85 selectorShortcuts,
86 visibleShortcuts,
87 };
88 }, [] );
89
90 if ( showTemplateSelector ) {
91 return (
92 <TemplateSelector
93 clientId={ clientId }
94 setAttributes={ setAttributes }
95 label={ __( 'Query', 'generateblocks' ) }
96 instructions={ __( 'Choose a layout to start with.', 'generateblocks' ) }
97 templates={ TEMPLATES }
98 />
99 );
100 }
101
102 return (
103 <>
104 <InspectorControls>
105 <BlockStyles
106 settingsTab={ (
107 <BlockSettings
108 { ...props }
109 />
110 ) }
111 stylesTab={ (
112 <BlockStylesBuilder
113 attributes={ attributes }
114 setAttributes={ setAttributes }
115 shortcuts={ shortcuts }
116 onStyleChange={ onStyleChange }
117 name={ name }
118 />
119 ) }
120 />
121 </InspectorControls>
122
123 <RootElement
124 name={ name }
125 clientId={ clientId }
126 >
127 <TagName { ...innerBlocksProps } />
128 </RootElement>
129 </>
130 );
131 }
132
133 const Edit = compose(
134 withHtmlAttributes,
135 withStyles,
136 withUniqueId
137 )( EditBlock );
138
139 export { Edit };
140