/* global wpforms_gutenberg_form_selector, JSX */ /* jshint es3: false, esversion: 6 */ /** * @param strings.update_wp_notice_head * @param strings.update_wp_notice_text * @param strings.update_wp_notice_link * @param strings.wpforms_empty_help * @param strings.wpforms_empty_info */ const { serverSideRender: ServerSideRender = wp.components.ServerSideRender } = wp; const { createElement, Fragment } = wp.element; const { registerBlockType } = wp.blocks; const { InspectorControls } = wp.blockEditor || wp.editor; const { SelectControl, ToggleControl, PanelBody, Placeholder } = wp.components; const { __ } = wp.i18n; const wpformsIcon = createElement( 'svg', { width: 20, height: 20, viewBox: '0 0 612 612', className: 'dashicon' }, createElement( 'path', { fill: 'currentColor', d: 'M544,0H68C30.445,0,0,30.445,0,68v476c0,37.556,30.445,68,68,68h476c37.556,0,68-30.444,68-68V68 C612,30.445,581.556,0,544,0z M464.44,68L387.6,120.02L323.34,68H464.44z M288.66,68l-64.26,52.02L147.56,68H288.66z M544,544H68 V68h22.1l136,92.14l79.9-64.6l79.56,64.6l136-92.14H544V544z M114.24,263.16h95.88v-48.28h-95.88V263.16z M114.24,360.4h95.88 v-48.62h-95.88V360.4z M242.76,360.4h255v-48.62h-255V360.4L242.76,360.4z M242.76,263.16h255v-48.28h-255V263.16L242.76,263.16z M368.22,457.3h129.54V408H368.22V457.3z', } ) ); /** * Popup container. * * @since 1.8.3 * * @type {Object} */ let $popup = {}; /** * Close button (inside the form builder) click event. * * @since 1.8.3 * * @param {string} clientID Block Client ID. */ const builderCloseButtonEvent = function( clientID ) { $popup .off( 'wpformsBuilderInPopupClose' ) .on( 'wpformsBuilderInPopupClose', function( e, action, formId, formTitle ) { if ( action !== 'saved' || ! formId ) { return; } // Insert a new block when a new form is created from the popup to update the form list and attributes. const newBlock = wp.blocks.createBlock( 'wpforms/form-selector', { formId: formId.toString(), // Expects string value, make sure we insert string. } ); // eslint-disable-next-line camelcase wpforms_gutenberg_form_selector.forms = [ { ID: formId, post_title: formTitle } ]; // Insert a new block. wp.data.dispatch( 'core/block-editor' ).removeBlock( clientID ); wp.data.dispatch( 'core/block-editor' ).insertBlocks( newBlock ); } ); }; /** * Init Modern style Dropdown fields (