PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.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 / shape / edit.js
generateblocks / src / blocks / shape Last commit date
components 1 year ago block.json 1 year ago edit.js 1 year ago index.js 1 year ago save.js 1 year ago
edit.js
111 lines
1 import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
2 import { 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 sanitizeSVG from '../../utils/sanitize-svg/index.js';
9 import RootElement from '../../components/root-element/index.js';
10 import { BlockSettings } from './components/BlockSettings';
11 import { withStyles } from '@hoc/withStyles';
12 import { BlockStylesBuilder } from '@components/index';
13 import { withHtmlAttributes } from '@hoc/withHtmlAttributes.js';
14 import { getBlockClasses } from '@utils/getBlockClasses.js';
15
16 function EditBlock( props ) {
17 const {
18 attributes,
19 setAttributes,
20 name,
21 clientId,
22 onStyleChange,
23 editorHtmlAttributes,
24 styles,
25 } = props;
26
27 const {
28 html,
29 } = attributes;
30
31 const classNames = getBlockClasses(
32 'gb-shape',
33 {
34 ...attributes,
35 styles,
36 },
37 true
38 );
39
40 const shortcuts = useMemo( () => {
41 const visibleSelectors = [
42 {
43 label: __( 'Main', 'generateblocks' ),
44 value: '',
45 },
46 ];
47
48 visibleSelectors.push(
49 {
50 label: 'SVG Element',
51 value: 'svg',
52 }
53 );
54
55 return {
56 selectorShortcuts: {},
57 visibleShortcuts: visibleSelectors,
58 };
59 }, [] );
60
61 const blockProps = useBlockProps(
62 {
63 className: classNames.join( ' ' ).trim(),
64 ...editorHtmlAttributes,
65 }
66 );
67
68 return (
69 <>
70 <InspectorControls>
71 <BlockStyles
72 settingsTab={ (
73 <BlockSettings
74 { ...props }
75 />
76 ) }
77 stylesTab={ (
78 <BlockStylesBuilder
79 attributes={ attributes }
80 setAttributes={ setAttributes }
81 shortcuts={ shortcuts }
82 onStyleChange={ onStyleChange }
83 name={ name }
84 />
85 ) }
86 />
87 </InspectorControls>
88 <RootElement
89 name={ name }
90 clientId={ clientId }
91 >
92 <span
93 { ...blockProps }
94 dangerouslySetInnerHTML={
95 { __html: sanitizeSVG( html ) }
96
97 }
98 />
99 </RootElement>
100 </>
101 );
102 }
103
104 const Edit = compose(
105 withHtmlAttributes,
106 withStyles,
107 withUniqueId
108 )( EditBlock );
109
110 export { Edit };
111