PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / framework / blocks-style-manager / assets / src / hoc-wrappers / with-block-class.js
jetformbuilder / modules / framework / blocks-style-manager / assets / src / hoc-wrappers Last commit date
with-block-class.js 3 months ago with-styles-controls.js 3 months ago
with-block-class.js
75 lines
1 import { createHigherOrderComponent } from '@wordpress/compose';
2 import { useSelect } from '@wordpress/data';
3 import { useEffect } from '@wordpress/element';
4
5 export const withBlockUniqueClass = createHigherOrderComponent( ( BlockListBlockComponent ) => {
6 return ( props ) => {
7 const {
8 name,
9 className = '',
10 clientId,
11 setAttributes,
12 attributes,
13 } = props;
14
15 // Pull the block’s registration info
16 const blockType = useSelect(
17 ( select ) => select( 'core/blocks' ).getBlockType( name ),
18 [ name ]
19 );
20
21 // If crocoblock_styles support is present, add our class
22 if ( blockType?.supports?.crocoblock_styles ) {
23
24 const uniqueClass = props?.attributes?.[ window.crocoStyleEditorData.support_name ]?.[ '_uniqueClassName' ];
25
26 useEffect( () => {
27 if ( window.crocoBlockStyleEditor.classIsUsed( uniqueClass, clientId ) ) {
28 // If the class is already used, we need to generate a new one
29 const newUniqueClass = generateUniqueClassName();
30
31 setAttributes( {
32 [ window.crocoStyleEditorData.support_name ]: {
33 ...attributes[ window.crocoStyleEditorData.support_name ],
34 _uniqueClassName: newUniqueClass,
35 },
36 } );
37 }
38 }, [] );
39
40 return (
41 <BlockListBlockComponent
42 { ...props }
43 className={ `${ className } ${ uniqueClass }`.trim() }
44 />
45 );
46 }
47
48 // Otherwise render unmodified
49 return <BlockListBlockComponent
50 { ...props }
51 />;
52 };
53 }, 'withBlockUniqueClass' );
54
55 export const generateUniqueClassName = () => {
56
57 const length = 8;
58
59 let chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
60 let result = '';
61
62 for ( let i = 0; i < length; i++ ) {
63
64 if ( i === 0 ) {
65 // Ensure the first character is a letter
66 result += chars.charAt( Math.floor( Math.random() * 26 ) );
67 continue;
68 }
69
70 result += chars.charAt( Math.floor( Math.random() * chars.length ) );
71 }
72
73 return window.crocoStyleEditorData.class_prefix + result;
74 }
75