PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.1.6
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 / editor / blocks / media-field / edit.js
jetformbuilder / assets / src / editor / blocks / media-field Last commit date
edit.js 2 years ago index.js 2 years ago options.js 2 years ago preview.js 2 years ago
edit.js
219 lines
1 import {
2 userAccess,
3 valueFormats,
4 } from './options';
5 import preview from './preview';
6
7 const {
8 ToolBarFields,
9 GeneralFields,
10 AdvancedFields,
11 FieldWrapper,
12 FieldSettingsWrapper,
13 ValidationBlockMessage,
14 ValidationToggleGroup,
15 AdvancedInspectorControl,
16 AttributeHelp,
17 } = JetFBComponents;
18 const {
19 useIsAdvancedValidation,
20 useUniqueNameOnDuplicate,
21 } = JetFBHooks;
22 const {
23 __,
24 } = wp.i18n;
25
26 const {
27 useBlockProps,
28 InspectorControls,
29 } = wp.blockEditor;
30
31 const {
32 SelectControl,
33 ToggleControl,
34 FormTokenField,
35 TextControl,
36 __experimentalNumberControl,
37 __experimentalInputControl,
38 PanelBody,
39 } = wp.components;
40
41 let { NumberControl, InputControl } = wp.components;
42
43 if ( typeof NumberControl === 'undefined' ) {
44 NumberControl = __experimentalNumberControl;
45 }
46
47 if ( typeof InputControl === 'undefined' ) {
48 InputControl = __experimentalInputControl;
49 }
50
51 const localizeData = window.jetFormMediaFieldData;
52
53 export default function MediaEdit( props ) {
54
55 const blockProps = useBlockProps();
56 const isAdvancedValidation = useIsAdvancedValidation();
57 useUniqueNameOnDuplicate();
58
59 const {
60 attributes,
61 setAttributes,
62 isSelected,
63 editProps: { uniqKey, attrHelp },
64 } = props;
65
66 if ( attributes.isPreview ) {
67 return <div style={ {
68 width: '100%',
69 display: 'flex',
70 justifyContent: 'center',
71 } }>
72 { preview }
73 </div>;
74 }
75
76 return [
77 <ToolBarFields
78 key={ uniqKey( 'ToolBarFields' ) }
79 { ...props }
80 />,
81 isSelected && (
82 <InspectorControls
83 key={ uniqKey( 'InspectorControls' ) }
84 >
85 <GeneralFields/>
86 <FieldSettingsWrapper { ...props }>
87 <SelectControl
88 key="allowed_user_cap"
89 label={ __( 'User access' ) }
90 labelPosition="top"
91 value={ attributes.allowed_user_cap }
92 onChange={ ( newValue ) => {
93 setAttributes( { allowed_user_cap: newValue } );
94 } }
95 options={ userAccess }
96 />
97 { 'any_user' !== attributes.allowed_user_cap && <>
98 <ToggleControl
99 key="insert_attachment"
100 label={ __( 'Insert attachment' ) }
101 checked={ attributes.insert_attachment }
102 help={ attrHelp( 'insert_attachment' ) }
103 onChange={ ( newValue ) => {
104 setAttributes( {
105 insert_attachment: Boolean( newValue ),
106 } );
107 } }
108 />
109 { attributes.insert_attachment && <SelectControl
110 key="value_format"
111 label={ __( 'Field value' ) }
112 labelPosition="top"
113 value={ attributes.value_format }
114 onChange={ ( newValue ) => {
115 props.setAttributes(
116 { value_format: newValue } );
117 } }
118 options={ valueFormats }
119 /> }
120 </> }
121 <AdvancedInspectorControl
122 value={ attributes.max_files }
123 label={ __( 'Maximum allowed files to upload',
124 'jet-form-builder' ) }
125 onChangePreset={ max_files => setAttributes(
126 { max_files } ) }
127 >
128 { ( { instanceId } ) => <TextControl
129 id={ instanceId }
130 className="jet-fb m-unset"
131 value={ attributes.max_files }
132 onChange={ max_files => setAttributes(
133 { max_files } ) }
134 /> }
135 </AdvancedInspectorControl>
136 <AttributeHelp name="max_files">
137 { __(
138 'If not set allow to upload 1 file.',
139 'jet-form-builder',
140 ) }
141 </AttributeHelp>
142 <AdvancedInspectorControl
143 value={ attributes.max_size }
144 label={ __( 'Maximum size in Mb',
145 'jet-form-builder' ) }
146 onChangePreset={ max_size => setAttributes(
147 { max_size } ) }
148 >
149 { ( { instanceId } ) => <TextControl
150 id={ instanceId }
151 className="jet-fb m-unset"
152 value={ attributes.max_size }
153 onChange={ max_size => setAttributes(
154 { max_size } ) }
155 /> }
156 </AdvancedInspectorControl>
157 <AttributeHelp name="max_size"/>
158 <TextControl
159 label={ __(
160 'Maximum file size message',
161 'jet-form-builder',
162 ) }
163 value={ attributes?.validation?.messages?.max_size ??
164 'Maximum file size: %max_size%' }
165 onChange={ max_size => {
166 setAttributes( {
167 validation: {
168 messages: { max_size },
169 },
170 } );
171 } }
172 help={ __(
173 `Use the %max_size% macro to display
174 the maximum allowed file size`,
175 'jet-form-builder',
176 ) }
177 />
178 <FormTokenField
179 key="allowed_mimes"
180 value={ attributes.allowed_mimes }
181 label={ __( 'Allow MIME types', 'jet-form-builder' ) }
182 suggestions={ localizeData.mime_types }
183 onChange={ allowed_mimes => setAttributes(
184 { allowed_mimes } ) }
185 tokenizeOnSpace
186 />
187 </FieldSettingsWrapper>
188 <PanelBody
189 title={ __( 'Validation', 'jet-form-builder' ) }
190 >
191 <ValidationToggleGroup/>
192 { isAdvancedValidation && <>
193 <ValidationBlockMessage name="max_files"/>
194 <ValidationBlockMessage name="file_max_size"/>
195 { Boolean( attributes.allowed_mimes.length ) && (
196 <ValidationBlockMessage name="file_ext"/>
197 ) }
198 </> }
199 </PanelBody>
200 <AdvancedFields
201 key={ uniqKey( 'AdvancedFields' ) }
202 { ...props }
203 />
204 </InspectorControls>
205 ),
206 <div { ...blockProps } key={ uniqKey( 'viewBlock' ) }>
207 <FieldWrapper
208 key={ uniqKey( 'FieldWrapper' ) }
209 { ...props }
210 >
211 <InputControl
212 key={ uniqKey( 'place_holder_block_new' ) }
213 type={ 'file' }
214 disabled={ true }
215 />
216 </FieldWrapper>
217 </div>,
218 ];
219 }