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 / looper / edit.js
generateblocks / src / blocks / looper Last commit date
components 1 year ago block.json 1 year ago edit.js 1 year ago editor.scss 1 year ago index.js 1 year ago save.js 1 year ago
edit.js
115 lines
1 import { useBlockProps, InspectorControls } 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 { LoopInnerBlocksRenderer } from './components/LoopInnerBlocksRenderer';
9 import { BlockSettings } from './components/BlockSettings';
10 import { selectorShortcuts as defaultSelectorShortcuts } from '@utils/selectorShortcuts.js';
11 import { withStyles } from '@hoc/withStyles';
12 import { BlockStylesBuilder } from '@components/index';
13
14 import './editor.scss';
15 import { withHtmlAttributes } from '@hoc/withHtmlAttributes.js';
16 import { getBlockClasses } from '@utils/getBlockClasses';
17
18 function EditBlock( props ) {
19 const {
20 attributes,
21 setAttributes,
22 onStyleChange,
23 editorHtmlAttributes,
24 styles,
25 } = props;
26
27 const {
28 tagName,
29 } = attributes;
30
31 const classNames = getBlockClasses(
32 'gb-looper',
33 {
34 ...attributes,
35 styles,
36 }
37 );
38
39 useEffect( () => {
40 if ( ! tagName ) {
41 setAttributes( { tagName: 'div' } );
42 }
43 }, [ tagName ] );
44
45 const blockProps = useBlockProps(
46 {
47 className: classNames.join( ' ' ).trim(),
48 ...editorHtmlAttributes,
49 }
50 );
51
52 const TagName = tagName || 'div';
53 const shortcuts = useMemo( () => {
54 const selectorShortcuts = {
55 ...defaultSelectorShortcuts,
56 default: {
57 items: [
58 { label: __( 'First item', 'generateblocks' ), value: '> .gb-loop-item:first-child' },
59 ...defaultSelectorShortcuts.default.items,
60 ],
61 },
62 };
63
64 const visibleSelectors = [];
65
66 if ( 'a' !== tagName ) {
67 visibleSelectors.push(
68 {
69 label: __( 'Links', 'generateblocks' ),
70 value: 'a',
71 }
72 );
73 }
74
75 return {
76 selectorShortcuts,
77 visibleShortcuts: visibleSelectors,
78 };
79 }, [ tagName ] );
80
81 return (
82 <>
83 <InspectorControls>
84 <BlockStyles
85 settingsTab={ (
86 <BlockSettings
87 { ...props }
88 />
89 ) }
90 stylesTab={ (
91 <BlockStylesBuilder
92 attributes={ attributes }
93 setAttributes={ setAttributes }
94 shortcuts={ shortcuts }
95 onStyleChange={ onStyleChange }
96 name={ name }
97 />
98 ) }
99 />
100 </InspectorControls>
101 <TagName { ...blockProps }>
102 <LoopInnerBlocksRenderer { ...props } />
103 </TagName>
104 </>
105 );
106 }
107
108 const Edit = compose(
109 withHtmlAttributes,
110 withStyles,
111 withUniqueId
112 )( EditBlock );
113
114 export { Edit };
115