芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/blocksy-companion/static/js/editor/blocks/search/Preview.js
import { createElement, useRef, useEffect, useState, useCallback, RawHTML, } from '@wordpress/element' import { RichText } from '@wordpress/block-editor' import { __ } from 'ct-i18n' import { Spinner } from '@wordpress/components' import useDynamicPreview from '../../hooks/useDynamicPreview' import { colors } from './colors' const OVERWRITE_ATTRIBUTES = { enable_live_results: 'no', live_results_images: 'yes', searchBoxHeight: '', searchProductPrice: 'no', searchProductStatus: 'no', search_box_placeholder: __('Search', 'blocksy-companion'), taxonomy_filter_label: __('Select category', 'blocksy-companion'), search_through: { post: true, page: true, product: true, custom: true }, taxonomy_filter_visibility: { desktop: true, tablet: true, mobile: false }, ...colors, } const Preview = ({ attributes, setAttributes, buttonStyles }) => { const [isChanging, setIsChanging] = useState(false) const { search_box_button_text, search_box_placeholder, taxonomy_filter_label, buttonPosition, has_taxonomy_filter, buttonUseText, } = attributes const maybeParts = useRef({ taxonomy: '', icon: '', }) const formatContent = useCallback( (content) => { const virtualContainer = document.createElement('div') virtualContainer.innerHTML = content const input = virtualContainer.querySelector('[type="search"]') if (input) { input.setAttribute('placeholder', search_box_placeholder) } const searchBox = virtualContainer.querySelector('.ct-search-box') searchBox.style = '' if (virtualContainer.querySelector('.ct-select-taxonomy')) { maybeParts.current = { ...maybeParts.current, taxonomy: virtualContainer.querySelector( '.ct-select-taxonomy' ).outerHTML, } } if (virtualContainer.querySelector('.ct-icon')) { maybeParts.current = { ...maybeParts.current, icon: virtualContainer.querySelector('.ct-icon').outerHTML, } } return virtualContainer.innerHTML }, [search_box_placeholder, buttonPosition, buttonStyles] ) const { isLoading } = useDynamicPreview( 'search', { ...attributes, ...OVERWRITE_ATTRIBUTES, }, formatContent ) useEffect(() => { setIsChanging(true) setTimeout(() => { setIsChanging(false) }, 100) }, [attributes]) return isLoading ? (
) : (
{ setAttributes({ search_box_placeholder: e.target.value, }) }} placeholder="Search" name="s" autocomplete="off" title="Search for..." aria-label="Search for..." />
{has_taxonomy_filter === 'yes' ? (
setAttributes({ taxonomy_filter_label: content, }) } />
) : null}
{buttonUseText === 'yes' ? (
setAttributes({ search_box_button_text: content, }) } /> ) : (
{maybeParts.current.icon}
)}
) } export default Preview