PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 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 All 134 releases
jetformbuilder / modules / framework / blocks-style-manager / assets / src / editor.js

editor.js in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/framework/blocks-style-manager/assets/src/editor.js

100 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import './editor.scss';
2 import { addFilter } from '@wordpress/hooks';
3 import { withStylesControls } from './hoc-wrappers/with-styles-controls';
4 import { withBlockUniqueClass } from './hoc-wrappers/with-block-class';
5
6 class CrocoBlockStyleEditor {
7
8 init() {
9
10 this.blocks = window?.crocoStyleEditorData?.blocks_supports || {};
11 this.supportName = window?.crocoStyleEditorData?.support_name;
12 this.defaults = window?.crocoStyleEditorData?.defaults || {};
13 this.usedClasses = {};
14
15 addFilter(
16 'blocks.registerBlockType',
17 'crocoblock-style-manager/enable-block-support',
18 this.registerBlock.bind( this )
19 );
20
21 addFilter(
22 'editor.BlockEdit',
23 'crocoblock-style-manager/enable-block-support',
24 withStylesControls
25 );
26
27 addFilter(
28 'editor.BlockListBlock',
29 'crocoblock-style-manager/with-crocoblock-editor-class',
30 withBlockUniqueClass,
31 0
32 );
33 }
34
35 classIsUsed( className, clientId ) {
36
37 if ( ! className || ! clientId ) {
38 return false;
39 }
40
41 if ( this.usedClasses[ className ] ) {
42 if ( this.usedClasses[ className ] === clientId ) {
43 // It's the same clientId, so we can use this class
44 return false;
45 } else {
46 // The class is already used by another block
47 return true;
48 }
49 } else {
50 // The class is not used yet, so we can use it
51 this.usedClasses[ className ] = clientId;
52 return false;
53 }
54 }
55
56 getBlockControls( blockName ) {
57 return this.blocks[ blockName ] || false;
58 }
59
60 registerBlock( settings, name ) {
61
62 if ( ! this.getBlockControls( name ) ) {
63 return settings;
64 }
65
66 const supports = settings.supports || {};
67 supports[ this.supportName ] = true;
68
69 const attributes = settings.attributes || {};
70
71 if ( ! attributes[ this.supportName ] ) {
72
73 let defaults = {
74 _uniqueClassName: '',
75 };
76
77 if ( this.defaults[ name ] ) {
78 defaults = {
79 ...defaults,
80 ...this.defaults[ name ],
81 };
82 }
83
84 attributes[ this.supportName ] = {
85 type: 'object',
86 default: defaults,
87 style: true,
88 };
89 }
90
91 return {
92 ...settings,
93 supports: supports,
94 attributes: attributes,
95 };
96 }
97 }
98
99 window.crocoBlockStyleEditor = new CrocoBlockStyleEditor();
100 window.crocoBlockStyleEditor.init();