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 / helpers / utils.js

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

82 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Get all block controls for given block
3 *
4 * @param {string} blockName
5 * @returns {object} blockControls
6 */
7 export const getBlockControls = ( blockName ) => {
8
9 const blockControls = window.crocoBlockStyleEditor.getBlockControls( blockName );
10
11 if ( ! blockControls ) {
12 return {};
13 }
14
15 return blockControls;
16 }
17
18 /**
19 * Check if given stack has children
20 *
21 * @param {object} stack
22 * @returns {boolean}
23 */
24 export const hasChildren = ( stack ) => {
25 if ( ! stack.children ) {
26 return false;
27 }
28
29 if ( Array.isArray( stack.children ) && stack.children.length > 0 ) {
30 return true;
31 }
32
33 // Otherwise, return false
34 return false;
35 }
36
37 /**
38 * Check if given variable is an object
39 *
40 * @param {any} variable
41 * @returns {boolean}
42 */
43 export const isObject = ( variable ) => {
44 return typeof variable === 'object' && variable !== null && !Array.isArray(variable);
45 }
46
47 export const isEmpty = ( variable ) => {
48
49 if ( variable === null || variable === undefined ) {
50 return true;
51 }
52
53 if ( typeof variable === 'string' && variable.trim() === '' ) {
54 return true;
55 }
56
57 if ( Array.isArray( variable ) && variable.length === 0 ) {
58 return true;
59 }
60
61 if ( isObject( variable ) && Object.keys( variable ).length === 0 ) {
62 return true;
63 }
64
65 return false;
66 }
67
68 export const valueIsEmpty = ( value ) => {
69
70 if ( isEmpty( value ) ) {
71 return true;
72 }
73
74 if ( isObject( value ) && Object.keys( value ).length > 0 ) {
75 if ( Object.values( value ).every( ( v ) => isEmpty( v ) ) ) {
76 return true;
77 }
78 }
79
80 return false;
81 }
82