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