import { jsonToObj, objToJson, borderStrToObj, objToBorderStr, boxShadowStrToObj, objToBoxShadowStr, toBoolean, boolToVerbose } from 'includes/utility'; import { pluginIcon } from 'includes/icons'; import BoxShadowControl from "includes/controls/box-shadow-control"; import BackgroundControl from "includes/controls/background-control"; import ColorPickerControl from "includes/controls/color-picker-control"; const { __ } = wp.i18n; const { merge } = window.lodash; const { registerPlugin } = wp.plugins; const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost; const { Fragment, useState } = wp.element; const { useEntityProp } = wp.coreData; const { useSelect, useDispatch } = wp.data; const { MediaUpload, } = wp.blockEditor; const { addFilter } = wp.hooks; const { PanelBody, BaseControl, Icon, Dashicon, TextControl, RangeControl, ToggleControl, ColorPicker, ColorIndicator, BoxControl, DateTimePicker, SelectControl, Button, RadioControl, __experimentalInputControl, __experimentalUnitControl, __experimentalBorderControl, __experimentalToggleGroupControl, __experimentalToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon, } = wp.components; let { InputControl, UnitControl, BorderControl, ToggleGroupControl, ToggleGroupControlOption, ToggleGroupControlOptionIcon } = wp.components; InputControl = InputControl || __experimentalInputControl; UnitControl = UnitControl || __experimentalUnitControl; BorderControl = BorderControl || __experimentalBorderControl; ToggleGroupControl = ToggleGroupControl || __experimentalToggleGroupControl; ToggleGroupControlOption = ToggleGroupControlOption || __experimentalToggleGroupControlOption; ToggleGroupControlOptionIcon = ToggleGroupControlOptionIcon || __experimentalToggleGroupControlOptionIcon; registerPlugin( 'jet-popup-sidebar', { render: () => { const _metaStyles = useSelect( function ( select ) { return select( 'core/editor' ).getEditedPostAttribute( 'meta' )[ '_styles' ]; }, [] ); const metaStyles = merge( {}, window.JetPopupBlockEditorPluginConfig.defaultStyleSettings || {}, _metaStyles ); const _metaSettings = useSelect( function ( select ) { return select( 'core/editor' ).getEditedPostAttribute( 'meta' )[ '_settings' ]; }, [] ); const metaSettings = Object.assign( {}, window.JetPopupBlockEditorPluginConfig.defaultSettings || {}, _metaSettings ); const postId = useSelect( function ( select ) { return select( 'core/editor' ).getCurrentPostId(); }, [] ); const editPost = useDispatch( 'core/editor' ).editPost; const updateMetaValue = ( id, value ) => { if ( 'undefined' === typeof value ) { return false; } let newMetaObj = {}; newMetaObj[ id ] = value; editPost( { meta: { _styles: Object.assign( {}, metaStyles, newMetaObj ) }, } ); }; const updateMetaValues = ( newMetaObj = {} ) => { editPost( { meta: { _styles: Object.assign( {}, metaStyles, newMetaObj ) }, } ); }; const updateSettingValue = ( id, value ) => { if ( 'undefined' === typeof value ) { return false; } let newMetaObj = {}; newMetaObj[ id ] = value; editPost( { meta: { _settings: Object.assign( {}, metaSettings, newMetaObj ) }, } ); }; const [ closeButtonIconUrl, setCloseButtonIconUrl ] = useState(); if ( metaSettings.close_button_icon ) { wp.media.attachment( metaSettings.close_button_icon ).fetch().then( ( data ) => { setCloseButtonIconUrl( data.url ); } ) } return ( { __( 'Jet Popup', 'jet-popup' ) } { updateSettingValue( 'jet_popup_animation', value ); } } /> { updateSettingValue( 'jet_popup_open_trigger', value ); } } /> { 'page-load' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_page_load_delay', value ); } } /> } { 'user-inactive' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_user_inactivity_time', value ); } } /> } { 'scroll-trigger' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_scrolled_to_value', value ); } } /> } { 'on-date' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_on_date_value', value.replace( 'T', ' ' ) ); } } __nextRemoveHelpButton __nextRemoveResetButton /> } { 'on-time' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_on_time_start_value', value ); } } /> } { 'on-time' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_on_time_end_value', value ); }} /> } { 'custom-selector' === metaSettings.jet_popup_open_trigger && { updateSettingValue( 'jet_popup_custom_selector', value ); }} /> } { updateSettingValue( 'jet_popup_prevent_scrolling', boolToVerbose( value ) ); } } /> { updateSettingValue( 'jet_popup_show_once', boolToVerbose( value ) ); } } /> { toBoolean( metaSettings.jet_popup_show_once ) && { updateSettingValue( 'jet_popup_show_again_delay', value ); } } /> } { updateSettingValue( 'jet_popup_use_ajax', boolToVerbose( value ) ); } } /> { toBoolean( metaSettings.jet_popup_use_ajax ) && { updateSettingValue( 'jet_popup_force_ajax', boolToVerbose( value ) ); } } /> } { updateSettingValue( 'use_close_button', boolToVerbose( value ) ); } } /> { toBoolean( metaSettings.use_close_button ) &&
{ closeButtonIconUrl && } { setCloseButtonIconUrl( media.url ); updateSettingValue( 'close_button_icon', media.id.toString() ); } } allowedTypes={ [ 'image/svg+xml' ] } value={ metaSettings.close_button_icon } render={ ( { open } ) => ( )} /> { closeButtonIconUrl && }
} { updateSettingValue( 'use_overlay', boolToVerbose( value ) ); } } /> { toBoolean( metaSettings.use_overlay ) && { updateSettingValue( 'close_on_overlay_click', boolToVerbose( value ) ); } } /> }
{ updateMetaValue( 'container_width', value ); } } isUnitSelectTabbable value={ metaStyles.container_width } /> { updateMetaValues( { container_custom_height: !metaStyles.container_custom_height, container_height: status ? metaStyles.container_height : '', } ); } } /> { metaStyles.container_custom_height && { updateMetaValue( 'container_height', value ); } } isUnitSelectTabbable value={ metaStyles.container_height } /> } updateMetaValue( 'container_hor_position', value ) } > updateMetaValue( 'container_ver_position', value ) } > updateMetaValue( 'content_ver_position', value ) } > { updateMetaValue( 'container_bg', newValue ); } } /> { updateMetaValue( 'container_hor_padding', value ); } } isUnitSelectTabbable value={ metaStyles.container_hor_padding } /> { updateMetaValue( 'container_ver_padding', value ); } } isUnitSelectTabbable value={ metaStyles.container_ver_padding } /> { updateMetaValue( 'container_ver_margin', value ); } } isUnitSelectTabbable value={ metaStyles.container_ver_margin } /> { updateMetaValue( 'container_hor_margin', value ); } } isUnitSelectTabbable value={ metaStyles.container_hor_margin } /> { updateMetaValue( 'container_border', objToBorderStr( value ) ); } } value={ borderStrToObj( metaStyles.container_border ) } /> { updateMetaValue( 'container_border_radius', value ); } } isUnitSelectTabbable value={ metaStyles.container_border_radius } /> { console.log(newValue) updateMetaValue( 'container_box_shadow', objToBoxShadowStr( newValue ) ); } } /> { updateMetaValue( 'z_index', value ); } } /> updateMetaValue( 'close_button_icon_color', value ) } /> { updateMetaValue( 'close_button_icon_size', value ); } } isUnitSelectTabbable value={ metaStyles.close_button_icon_size } /> updateMetaValue( 'close_button_bg_color', value ) } /> { updateMetaValue( 'close_button_size', value ); } } isUnitSelectTabbable value={ metaStyles.close_button_size } /> { updateMetaValue( 'close_button_border', objToBorderStr( value ) ); } } value={ borderStrToObj( metaStyles.close_button_border ) } /> { updateMetaValue( 'close_button_border_radius', value ); } } isUnitSelectTabbable value={ metaStyles.close_button_border_radius } /> { updateMetaValue( 'close_button_translate_x', value ); } } isUnitSelectTabbable value={ metaStyles.close_button_translate_x } /> { updateMetaValue( 'close_button_translate_y', value ); } } isUnitSelectTabbable value={ metaStyles.close_button_translate_y } /> { updateMetaValue( 'overlay_bg', newValue ); } } />
) } } );