calculated-field
2 years ago
checkbox-field
2 years ago
color-picker-field
2 years ago
conditional-block
2 years ago
controls
2 years ago
date-field
2 years ago
datetime-field
2 years ago
form-break-field
2 years ago
form-break-start
2 years ago
group-break-field
2 years ago
heading-field
2 years ago
hidden-field
2 years ago
media-field
2 years ago
number-field
2 years ago
progress-bar
2 years ago
radio-field
2 years ago
range-field
2 years ago
repeater-field
2 years ago
select-field
2 years ago
submit-field
2 years ago
text-field
2 years ago
textarea-field
2 years ago
time-field
2 years ago
wysiwyg-field
2 years ago
base-block.json
2 years ago
block-wrappers.js
2 years ago
form-fields.js
2 years ago
help-messages-config.js
2 years ago
select-radio-chekc-options.js
2 years ago
block-wrappers.js
68 lines
| 1 | import { messagesConfig } from "./help-messages-config"; |
| 2 | |
| 3 | const { |
| 4 | applyFilters |
| 5 | } = wp.hooks; |
| 6 | |
| 7 | export function withCustomProps( block ) { |
| 8 | const { edit: EditComponent } = block.settings; |
| 9 | |
| 10 | let _plugins = {}; |
| 11 | |
| 12 | if ( 'useEditProps' in block.settings ) { |
| 13 | const { useEditProps } = block.settings; |
| 14 | |
| 15 | useEditProps.forEach( name => { |
| 16 | const editProp = editProps.find( prop => name === prop.name ); |
| 17 | |
| 18 | if ( editProp ) { |
| 19 | _plugins[ name ] = editProp.callable( block ); |
| 20 | } |
| 21 | } ); |
| 22 | |
| 23 | delete block.settings.useEditProps; |
| 24 | } |
| 25 | |
| 26 | return props => <EditComponent { ...props } editProps={ { ..._plugins } }/>; |
| 27 | } |
| 28 | |
| 29 | const getHelpInstance = block => { |
| 30 | const messages = {}; |
| 31 | |
| 32 | messagesConfig.forEach( msg => { |
| 33 | if ( msg.to.includes( block.name ) && msg.message ) { |
| 34 | messages[ msg.attribute ] = msg; |
| 35 | } |
| 36 | } ); |
| 37 | |
| 38 | return ( attribute, attributes = {} ) => { |
| 39 | if ( ! ( attribute in messages ) ) { |
| 40 | return ''; |
| 41 | } |
| 42 | const item = messages[ attribute ]; |
| 43 | |
| 44 | if ( 'conditions' in item ) { |
| 45 | for ( const attrName in item.conditions ) { |
| 46 | if ( ! ( attrName in attributes ) || item.conditions[ attrName ] !== attributes[ attrName ] ) { |
| 47 | return; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | return item.message; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | const editProps = applyFilters( 'jet.fb.register.editProps', [ |
| 56 | { |
| 57 | name: 'uniqKey', |
| 58 | callable: block => ( suffix => `${ block.name }/${ suffix }` ) |
| 59 | }, |
| 60 | { |
| 61 | name: 'blockName', |
| 62 | callable: block => block.name |
| 63 | }, |
| 64 | { |
| 65 | name: 'attrHelp', |
| 66 | callable: getHelpInstance |
| 67 | } |
| 68 | ] ); |