Server IP : 104.21.93.192 / Your IP : 216.73.216.73 Web Server : LiteSpeed System : Linux premium900.web-hosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 User : redwjova ( 1790) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/redwjova/near.llc/wp-content/plugins/extendify/src/Library/components/ |
Upload File : |
import { BlockPreview } from '@wordpress/block-editor'; import { rawHandler } from '@wordpress/blocks'; import { useMemo, useRef, useState, useEffect } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import classNames from 'classnames'; import { usePreviewIframe } from '@library/hooks/usePreviewIframe'; export const BlockPreviewButton = ({ insertPattern, code }) => { const [ready, setReady] = useState(false); const blockRef = useRef(); const blocks = useMemo( () => rawHandler({ HTML: lowerImageQuality(code) }), [code], ); const { ready: show } = usePreviewIframe({ container: blockRef.current, ready, onIFrameLoaded: () => undefined, loadDelay: 50, }); useEffect(() => setReady(true), []); return ( <button ref={blockRef} type="button" aria-label={__('Insert Pattern', 'extendify-local')} className={classNames( 'library-pattern relative z-10 m-0 mb-8 inline-block w-full cursor-pointer border bg-transparent p-0 focus:shadow-sm focus:outline-none focus:ring-wp focus:ring-design-main focus:ring-offset-2 focus:ring-offset-[#FAFAFA]', { 'border-transparent opacity-0': !show, 'border-gray-400 opacity-100': show, }, )} onClick={() => insertPattern(blocks)}> <BlockPreview blocks={blocks} live={false} viewportWidth={1400} additionalStyles={[ { css: '.rich-text [data-rich-text-placeholder]:after { content: "" }', }, ]} /> </button> ); }; const lowerImageQuality = (html) => { return html.replace( /(https?:\/\/\S+\?w=\d+)/gi, '$1&q=10&auto=format,compress&fm=avif', ); };