Skip to content

Commit

Permalink
Merge pull request #34 from michelegiorgi/development
Browse files Browse the repository at this point in the history
release 1.3.6
  • Loading branch information
michelegiorgi authored Aug 8, 2021
2 parents 047c7fc + db5f7ae commit 0af15d6
Show file tree
Hide file tree
Showing 29 changed files with 1,441 additions and 1,369 deletions.
21 changes: 15 additions & 6 deletions admin/class-formality-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ public function register_blocks() {
}

public function enqueue_scripts() {
global $pagenow;
$editor = get_post_type() == 'formality_form' ? 'formality' : str_replace(".php", "", $pagenow);
$upload = wp_upload_dir();
$formats = array();
$mimes = get_allowed_mime_types();
$maxsize = wp_max_upload_size() / 1048576;
if(!empty($mimes)) {
foreach ($mimes as $type => $mime) {
$multiple = explode("|", $type);
foreach ($multiple as $single) {
$formats[] = $single;
}
foreach ($multiple as $single) { $formats[] = $single; }
}
}
wp_enqueue_script( $this->formality . "-editor", plugin_dir_url(__DIR__) . 'dist/scripts/formality-editor.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-plugins', 'wp-edit-post' ), $this->version, false );
$dependecies = array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-plugins', 'wp-dom-ready', 'wp-components');
$dependecies[] = $editor == 'widgets' ? 'wp-edit-widgets' : 'wp-edit-post';
wp_enqueue_script( $this->formality . "-editor", plugin_dir_url(__DIR__) . 'dist/scripts/formality-editor.js', $dependecies, $this->version, false );
wp_localize_script( $this->formality . "-editor", 'formality', array(
'plugin_url' => str_replace('admin/', '', plugin_dir_url( __FILE__ )),
'templates_url' => $upload['baseurl'] . '/formality/templates',
Expand All @@ -61,7 +63,8 @@ public function enqueue_scripts() {
'api' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest'),
'upload_formats' => $formats,
'upload_max' => $maxsize
'upload_max' => $maxsize,
'editor' => $editor
));
wp_set_script_translations( $this->formality . "-editor", 'formality', plugin_dir_path( __DIR__ ) . 'languages' );
}
Expand Down Expand Up @@ -97,7 +100,7 @@ public function block_categories($categories, $post) {

public function filter_blocks($allowed_block_types, $editorcontext) {
$post = property_exists($editorcontext, 'post') ? $editorcontext->post : $editorcontext;
if ( $post->post_type == 'formality_form' ) { return $this->get_allowed('blocks'); }
if(!empty($post) && $post->post_type == 'formality_form') { return $this->get_allowed('blocks'); }
return $allowed_block_types;
}

Expand Down Expand Up @@ -260,4 +263,10 @@ public function prevent_classic_editor($can_edit, $post) {
return $can_edit;
}

public function remove_editor_styles() {
global $current_screen;
if('formality_form' == $current_screen->post_type) {
remove_editor_styles();
}
}
}
59 changes: 41 additions & 18 deletions assets/scripts/editor.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
// Formality editor scripts

import './editor/main/init.js';
import './editor/main/sidebar.js';
import { pageLoad } from './editor/utility/init.js';

import './editor/components/repeaterControl.js';

import './editor/blocks/text.js';
import './editor/blocks/textarea.js';
import './editor/blocks/email.js';
import './editor/blocks/number.js';
import './editor/blocks/select.js';
import './editor/blocks/multiple.js';
import './editor/blocks/switch.js';
import './editor/blocks/rating.js';
import './editor/blocks/upload.js';

import './editor/blocks/step.js';
import './editor/blocks/message.js';
import './editor/blocks/media.js';

import './editor/blocks/widget.js';
import { formSidebar } from './editor/plugins/sidebar.js';

import { textBlock } from './editor/blocks/text.js';
import { textareaBlock } from './editor/blocks/textarea.js';
import { emailBlock } from './editor/blocks/email.js';
import { numberBlock } from './editor/blocks/number.js';
import { selectBlock } from './editor/blocks/select.js';
import { multipleBlock } from './editor/blocks/multiple.js';
import { switchBlock } from './editor/blocks/switch.js';
import { ratingBlock } from './editor/blocks/rating.js';
import { uploadBlock } from './editor/blocks/upload.js';
import { stepBlock } from './editor/blocks/step.js';
import { messageBlock } from './editor/blocks/message.js';
import { mediaBlock } from './editor/blocks/media.js';
import { widgetBlock } from './editor/blocks/widget.js';

if(formality.editor=='formality') {

pageLoad()

formSidebar()

textBlock()
textareaBlock()
emailBlock()
numberBlock()
selectBlock()
multipleBlock()
switchBlock()
ratingBlock()
uploadBlock()
stepBlock()
messageBlock()
mediaBlock()

} else {

widgetBlock()

}
140 changes: 72 additions & 68 deletions assets/scripts/editor/blocks/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,75 +34,79 @@ const {

import { iconEmail as blockicon } from '../utility/icons.js'

registerBlockType( blockName, {
title: __('E-mail', 'formality'),
description: __('Text field that accepts only valid email address.', 'formality'),
icon: blockicon,
category: 'formality',
attributes: {
uid: { type: 'string', default: '' },
name: { type: 'string', default: ''},
label: { type: 'string', default: ''},
halfwidth: { type: 'boolean', default: false },
placeholder: { type: 'string', default: ''},
required: { type: 'boolean', default: false },
value: { type: 'string', default: ''},
rules: { type: 'string|array', attribute: 'rules', default: [], },
dbg: { type: 'string|object', default: {}, },
preview: { type: 'boolean', default: false },
},
example: { attributes: { preview: true } },
supports: {
html: false,
customClassName: false,
},
transforms: {
from: [{
type: 'block',
blocks: getBlockTypes(blockName),
transform: function ( attributes ) { return createBlock( blockName, attributes); },
}],
},
edit(props) {
export function emailBlock() {

checkUID(props)
let { name, label, placeholder, required, uid, value, rules, preview } = props.attributes
let focus = props.isSelected
if ( preview ) { return getPreview(props.name) }
registerBlockType( blockName, {
title: __('E-mail', 'formality'),
description: __('Text field that accepts only valid email address.', 'formality'),
icon: blockicon,
category: 'formality',
attributes: {
uid: { type: 'string', default: '' },
name: { type: 'string', default: ''},
label: { type: 'string', default: ''},
halfwidth: { type: 'boolean', default: false },
placeholder: { type: 'string', default: ''},
required: { type: 'boolean', default: false },
value: { type: 'string', default: ''},
rules: { type: 'string|array', attribute: 'rules', default: [], },
dbg: { type: 'string|object', default: {}, },
preview: { type: 'boolean', default: false },
},
example: { attributes: { preview: true } },
supports: {
html: false,
customClassName: false,
},
transforms: {
from: [{
type: 'block',
blocks: getBlockTypes(blockName),
transform: function ( attributes ) { return createBlock( blockName, attributes); },
}],
},
edit(props) {

return ([
<InspectorControls>
<PanelBody title={__('Field options', 'formality')}>
{ mainOptions(props) }
</PanelBody>
{ advancedPanel(props) }
</InspectorControls>
,
<div
className={ "formality__field formality__field--email" + ( focus ? ' formality__field--focus' : '' ) + ( required ? ' formality__field--required' : '' ) + ( value ? ' formality__field--filled' : '' ) }
>
<div
className="formality__label"
>
{ inlineName(props) }
<Icon icon={ hasRules(rules) ? "hidden" : "" } />
</div>
checkUID(props)
let { name, label, placeholder, required, uid, value, rules, preview } = props.attributes
let focus = props.isSelected
if ( preview ) { return getPreview(props.name) }

return ([
<InspectorControls>
<PanelBody title={__('Field options', 'formality')}>
{ mainOptions(props) }
</PanelBody>
{ advancedPanel(props) }
</InspectorControls>
,
<div
className="formality__input"
className={ "formality__field formality__field--email" + ( focus ? ' formality__field--focus' : '' ) + ( required ? ' formality__field--required' : '' ) + ( value ? ' formality__field--filled' : '' ) }
>
<input
type="text"
id={ uid }
name={ uid }
value={value}
placeholder={ placeholder ? placeholder : __('Type your answer here', 'formality') }
/>
<div className="formality__input__status" data-placeholder={ placeholder ? placeholder : __('Type your answer here', 'formality') }/>
</div>
</div>,
])
},
save () {
return null
},
});
<div
className="formality__label"
>
{ inlineName(props) }
<Icon icon={ hasRules(rules) ? "hidden" : "" } />
</div>
<div
className="formality__input"
>
<input
type="text"
id={ uid }
name={ uid }
value={value}
placeholder={ placeholder ? placeholder : __('Type your answer here', 'formality') }
/>
<div className="formality__input__status" data-placeholder={ placeholder ? placeholder : __('Type your answer here', 'formality') }/>
</div>
</div>,
])
},
save () {
return null
},
});

}
Loading

0 comments on commit 0af15d6

Please sign in to comment.