PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
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 / assets / src / package / blocks / components / FieldControl.js
jetformbuilder / assets / src / package / blocks / components Last commit date
AdvancedFields.js 2 years ago AttributeHelp.js 2 years ago BlockAddPrevButton.js 2 years ago BlockAdvancedValue.js 2 years ago BlockClassName.js 2 years ago BlockDefaultValue.js 2 years ago BlockDescription.js 2 years ago BlockLabel.js 2 years ago BlockName.js 2 years ago BlockPlaceholder.js 2 years ago BlockPrevButtonLabel.js 2 years ago BlockRequired.js 2 years ago BlockVisibility.js 2 years ago FieldControl.js 2 years ago FieldSettingsWrapper.js 2 years ago FieldWrapper.js 2 years ago GeneralFields.js 2 years ago SelectVariations.js 2 years ago ToggleGroupVariations.js 2 years ago ToolBarDefault.js 2 years ago ToolBarFields.js 2 years ago
FieldControl.js
198 lines
1 import ControlsSettings from '../helpers/ControlsSettings';
2
3 const {
4 useBlockProps,
5 } = wp.blockEditor;
6 const {
7 TextControl,
8 SelectControl,
9 ToggleControl,
10 BaseControl,
11 __experimentalNumberControl,
12
13 } = wp.components;
14
15 let { NumberControl } = wp.components;
16
17 if ( typeof NumberControl === 'undefined' ) {
18 NumberControl = __experimentalNumberControl;
19 }
20
21 function useControls( {
22 type,
23 attributes,
24 attrsSettings = {},
25 } ) {
26 const blockProps = useBlockProps();
27 const blockName = blockProps[ 'data-type' ];
28 const controls = ControlsSettings();
29
30 if ( !controls[ type ] ) {
31 return [];
32 }
33
34 const currentControl = controls[ type ];
35
36 const isValidCondition = ( attr ) => {
37 if ( !attr.condition ) {
38 return true;
39 }
40
41 if ( blockName && attr.condition.blockName ) {
42 if ( 'string' === typeof attr.condition.blockName && blockName !==
43 attr.condition.blockName ) {
44 return false;
45 }
46 if ( 'object' === typeof attr.condition.blockName
47 && attr.condition.blockName.length
48 && !attr.condition.blockName.includes( blockName )
49 ) {
50 return false;
51 }
52 }
53
54 const objectNotMatch = (
55 function () {
56 if ( 'object' !== typeof attr.condition.attr ) {
57 return true;
58 }
59 const { operator = 'and', items = {} } = attr.condition.attr;
60
61 if ( 'or' === operator.toLowerCase() ) {
62 for ( const attrToCompare in items ) {
63 const valueCompare = items[ attrToCompare ];
64
65 if ( valueCompare === attributes[ attrToCompare ] ) {
66 return true;
67 }
68 }
69 }
70
71 if ( 'and' === operator.toLowerCase() ) {
72 return (
73 function () {
74 for ( const attrToCompare in items ) {
75 if ( items[ attrToCompare ] !==
76 attributes[ attrToCompare ] ) {
77 return false;
78 }
79 }
80 return true;
81 }
82 )();
83 }
84
85 return true;
86 }
87 )();
88
89 if ( !objectNotMatch
90 || (
91 'string' === typeof attr.condition.attr
92 && attr.condition.attr
93 && !attributes[ attr.condition.attr ]
94 )
95 || (
96 'string' === typeof attr.condition
97 && !attributes[ attr.condition ]
98 )
99 ) {
100 return false;
101 }
102
103 return true;
104 };
105
106 return currentControl.attrs.filter(
107 ( { help = '', attrName, label, ...attr } ) => {
108 const isRegisterAttribute = (
109 attrName in attributes
110 );
111 const validCondition = isValidCondition( attr );
112 const isHidden = (
113 attrName in attrsSettings
114 && 'show' in attrsSettings[ attrName ]
115 && false === attrsSettings[ attrName ].show
116 );
117
118 return (
119 isRegisterAttribute && validCondition && !isHidden
120 );
121 } );
122 }
123
124 /**
125 * @deprecated 3.0.0
126 *
127 * @param props
128 * @return {unknown[]}
129 * @constructor
130 */
131 function FieldControl( props ) {
132 let {
133 setAttributes,
134 attributes,
135 } = props;
136
137 const fieldControls = useControls( props );
138
139 const onChangeValue = ( value, key ) => {
140 setAttributes( { [ key ]: value } );
141 };
142
143 return fieldControls.map( ( { help = '', attrName, label, ...attr } ) => {
144 switch ( attr.type ) {
145 case 'text':
146 return <TextControl
147 key={ `${ attr.type }-${ attrName }-TextControl` }
148 label={ label }
149 help={ help }
150 value={ attributes[ attrName ] }
151 onChange={ newVal => onChangeValue( newVal, attrName ) }
152 />;
153
154 case 'select':
155 return <SelectControl
156 key={ `${ attr.type }-${ attrName }-SelectControl` }
157 label={ label }
158 help={ help }
159 value={ attributes[ attrName ] }
160 options={ attr.options }
161 onChange={ newVal => {
162 onChangeValue( newVal, attrName );
163 } }
164 />;
165 case 'toggle':
166 return <ToggleControl
167 key={ `${ attr.type }-${ attrName }-ToggleControl` }
168 label={ label }
169 help={ help }
170 checked={ attributes[ attrName ] }
171 onChange={ newVal => {
172 onChangeValue( newVal, attrName );
173 } }
174 />;
175 case 'number':
176 return <BaseControl
177 key={ `${ attr.type }-${ attrName }-BaseControl` }
178 label={ label }
179 >
180 <NumberControl
181 key={ `${ attr.type }-${ attrName }-NumberControl` }
182 value={ attributes[ attrName ] }
183 onChange={ newVal => {
184 onChangeValue( Number( newVal ), attrName );
185 } }
186 />
187 <p className={ 'components-base-control__help' }
188 style={ {
189 color: 'rgb(117, 117, 117)',
190 } }>{ help }</p>
191 </BaseControl>;
192 }
193
194 } );
195
196 }
197
198 export default FieldControl;