import { useRef, useState, useEffect, createElement, Fragment, } from '@wordpress/element' import { __ } from 'ct-i18n' import saveAs from './file-saver' import { Overlay } from 'blocksy-options' import classnames from 'classnames' import phpUnserialize from 'phpunserialize' const CustomizerOptionsManager = () => { const [futureConfig, setFutureConfig] = useState(null) const [isCopyingOptions, setIsCopyingOptions] = useState(null) const [isDraggedOver, setIsDraggerOver] = useState(false) const [isExporting, setIsExporting] = useState(false) const [isImporting, setIsImporting] = useState(false) const [dataToExport, setDataToExport] = useState(['options']) const inputRef = useRef() const dropZoneRef = useRef() useEffect(() => { const onDragOver = (e) => { e.stopPropagation() e.preventDefault() e.dataTransfer.dropEffect = 'copy' setIsDraggerOver(true) } const onDragLeave = (e) => { e.stopPropagation() e.preventDefault() setIsDraggerOver(false) } const onDrop = (e) => { e.stopPropagation() e.preventDefault() setIsDraggerOver(false) const files = Array.from(e.dataTransfer.files || []) const items = Array.from(e.dataTransfer.items || []) if (items.length > 0) { const futureConfig = e.dataTransfer.items[0].getAsFile() setFutureConfig(futureConfig) } else { if (files.length > 0) { setFutureConfig(files[0]) } } } dropZoneRef.current.addEventListener('dragover', onDragOver, false) dropZoneRef.current.addEventListener('dragleave', onDragLeave, false) dropZoneRef.current.addEventListener('drop', onDrop, false) return () => { if (dropZoneRef.current) { dropZoneRef.current.removeEventListener( 'dragover', onDragOver, false ) dropZoneRef.current.removeEventListener( 'dragleave', onDragLeave, false ) dropZoneRef.current.removeEventListener('drop', onDrop, false) } } }, []) return (

{__('Export Options', 'blocksy-companion')}

{__( 'Easily export the theme customizer settings.', 'blocksy-companion' )}

{__('Import Options', 'blocksy-companion')}

{__( 'Easily import the theme customizer settings.', 'blocksy-companion' )}
{ setFutureConfig(config) }} />
{ct_customizer_localizations.has_child_theme && (

{__('Copy Options', 'blocksy-companion')}

{__( 'Copy and import your customizations from parent or child theme.', 'blocksy-companion' )}
{ct_customizer_localizations.is_parent_theme && (
)} {!ct_customizer_localizations.is_parent_theme && (
)}
)} setIsCopyingOptions(false)} render={() => (

{!ct_customizer_localizations.is_parent_theme && __( 'Copy From Parent Theme', 'blocksy-companion' )} {ct_customizer_localizations.is_parent_theme && __( 'Copy From Child Theme', 'blocksy-companion' )}

{!ct_customizer_localizations.is_parent_theme && __( 'You are about to copy all the settings from your parent theme into the child theme. Are you sure you want to continue?', 'blocksy-companion' )} {ct_customizer_localizations.is_parent_theme && __( 'You are about to copy all the settings from your child theme into the parent theme. Are you sure you want to continue?', 'blocksy-companion' )}

)} /> setIsExporting(false)} render={() => (

{__('Export Settings', 'blocksy-companion')}

{__( 'Choose what set of settings you want to export.', 'blocksy-companion' )}

{['options', 'widgets'].map((component) => (
{ if ( dataToExport.length === 1 && dataToExport[0] === component ) { return } setDataToExport((dataToExport) => dataToExport.includes(component) ? dataToExport.filter( (c) => c !== component ) : [...dataToExport, component] ) }}> { { options: __( 'Customizer settings', 'blocksy-companion' ), widgets: __( 'Widgets settings', 'blocksy-companion' ), }[component] }
))}
)} />
) } export default CustomizerOptionsManager