deprecations
2 years ago
condition.group.item.js
2 years ago
conditional.model.context.js
2 years ago
conditions.is.empty.js
2 years ago
conditions.list.js
2 years ago
conditions.modal.content.js
2 years ago
conditions.modal.js
2 years ago
edit.js
2 years ago
index.js
2 years ago
options.js
2 years ago
preview.js
2 years ago
save.js
2 years ago
index.js
90 lines
| 1 | import ConditionalBlockEdit from './edit'; |
| 2 | import metadata from '@blocks/conditional-block/block.json'; |
| 3 | import ConditionalSave from './save'; |
| 4 | import v3 from './deprecations/v3'; |
| 5 | |
| 6 | const { __, sprintf } = wp.i18n; |
| 7 | |
| 8 | const { createBlock, createBlocksFromInnerBlocksTemplate } = wp.blocks; |
| 9 | |
| 10 | const { name, icon = '' } = metadata; |
| 11 | |
| 12 | /** |
| 13 | * Available items for `useEditProps`: |
| 14 | * - uniqKey |
| 15 | * - formFields |
| 16 | * - blockName |
| 17 | * - attrHelp |
| 18 | */ |
| 19 | const settings = { |
| 20 | icon: <span dangerouslySetInnerHTML={ { __html: icon } }></span>, |
| 21 | description: __( |
| 22 | `Utilize the Conditional Visibility functionality allowing |
| 23 | to make fields of the form invisible to the users until some conditions are met.`, |
| 24 | 'jet-form-builder', |
| 25 | ), |
| 26 | edit: ConditionalBlockEdit, |
| 27 | save: ConditionalSave, |
| 28 | useEditProps: [ 'uniqKey' ], |
| 29 | jfbGetFields: () => [], |
| 30 | /** |
| 31 | * @param attributes |
| 32 | * @param context {{|'accessibility'|'visual'|'list-view'}} |
| 33 | * @returns {*} |
| 34 | * @private |
| 35 | */ |
| 36 | __experimentalLabel: ( attributes, { context } ) => { |
| 37 | if ( context !== 'list-view' ) { |
| 38 | return; |
| 39 | } |
| 40 | const funcObject = wp.data.select( 'jet-forms/block-conditions' ). |
| 41 | getFunction( |
| 42 | attributes?.func_type, |
| 43 | ); |
| 44 | |
| 45 | const funcLabel = funcObject?.label; |
| 46 | const conditionsCount = attributes?.conditions?.reduce( |
| 47 | ( prev, current ) => current?.or_operator ? prev : prev + 1, |
| 48 | 0, |
| 49 | ) ?? 0; |
| 50 | |
| 51 | return sprintf( |
| 52 | __( '%s %d condition(s)', 'jet-form-builder' ), |
| 53 | funcLabel, |
| 54 | conditionsCount, |
| 55 | ); |
| 56 | }, |
| 57 | example: { |
| 58 | attributes: { |
| 59 | isPreview: true, |
| 60 | }, |
| 61 | }, |
| 62 | transforms: { |
| 63 | from: [ |
| 64 | { |
| 65 | type: 'block', |
| 66 | blocks: [ '*' ], |
| 67 | isMultiBlock: true, |
| 68 | __experimentalConvert: blocks => { |
| 69 | const innerBlocksTemplate = blocks.map( ( { |
| 70 | name, |
| 71 | attributes, |
| 72 | innerBlocks, |
| 73 | } ) => [ name, { ...attributes }, innerBlocks ] ); |
| 74 | |
| 75 | return createBlock( name, {}, |
| 76 | createBlocksFromInnerBlocksTemplate( |
| 77 | innerBlocksTemplate ) ); |
| 78 | }, |
| 79 | priority: 0, |
| 80 | }, |
| 81 | ], |
| 82 | }, |
| 83 | deprecated: [ v3 ], |
| 84 | }; |
| 85 | |
| 86 | export { |
| 87 | metadata, |
| 88 | name, |
| 89 | settings, |
| 90 | }; |