/** * The embed workspace, a page like the settings: the ways to show the form (in a page, on its own * page, as a popup, as a button in a corner, on another website) in the list at the side, and a card * with the settings and the code of the chosen one, a copy button, the steps to use it and a sketch * of where the form appears. */ import React, { useEffect, useState } from 'react'; import { DEFAULT_FRAME, DEFAULT_POPUP, DEFAULT_WIDGET, type EmbedConfig, type FrameSettings, type PopupSettings, type WidgetSettings } from '../embed'; import { useBuilder, useEnv } from './context'; import { CodeBox, Steps, type EmbedMethod } from './EmbedParts'; import { EmbedProPanel } from './EmbedPro'; import { __, sprintf } from './i18n'; import { LegacyNotice } from './LegacyNotice'; import { addressOf, cleanSlug, PageAddressHint } from './Settings'; import { Button, Notice, ProBadge, ProList, TextInput } from './ui'; type InlineTarget = 'shortcode' | 'block' | 'elementor'; const METHOD_ICONS: Record = { inline: , link: , external: , popup: , widget: , }; function Line( { d }: { d: string } ) { return ( ); } /** The ways to embed, in the order of the list; pro marks those Funnelforms Free names only. */ function methods(): Array<{ id: EmbedMethod; title: string; text: string; pro: boolean }> { return [ { id: 'inline', title: __( 'Inline embedding', 'funnelforms-pro' ), text: __( 'Show the form inside a page or post of this website.', 'funnelforms-pro' ), pro: false }, { id: 'link', title: __( 'Direct link', 'funnelforms-pro' ), text: __( 'Share a link to the form on a page of its own.', 'funnelforms-pro' ), pro: false }, { id: 'popup', title: __( 'Popup', 'funnelforms-pro' ), text: __( 'Show the form in a popup when it is triggered.', 'funnelforms-pro' ), pro: true }, { id: 'widget', title: __( 'Widget', 'funnelforms-pro' ), text: __( 'Add a floating button that opens the form on a click.', 'funnelforms-pro' ), pro: true }, { id: 'external', title: __( 'Other website', 'funnelforms-pro' ), text: __( 'Embed the form on a website outside WordPress.', 'funnelforms-pro' ), pro: true }, ]; } export function EmbedWorkspace( { config }: { config?: EmbedConfig | null } ) { const form = useBuilder( ( s ) => s.form ); const [ method, setMethod ] = useState( 'inline' ); const [ popup, setPopup ] = useState( DEFAULT_POPUP ); const [ widget, setWidget ] = useState( DEFAULT_WIDGET ); const [ frame, setFrame ] = useState( DEFAULT_FRAME ); if ( ! form ) { return null; } const free = 'free' === process.env.FUNNELFORMS_EDITION; const list = methods(); const chosen = list.find( ( m ) => m.id === method ) ?? { title: '', text: '', pro: false }; let body: React.ReactNode; if ( 'inline' === method ) { body = ; } else if ( 'link' === method ) { body = ; } else { body = 'free' === process.env.FUNNELFORMS_EDITION ? ( ) : ( ); } // The same page as the settings: the ways as the list at the side, the chosen one as a card. return (

{ chosen.title }

{ free && chosen.pro ? : null }

{ chosen.text }

{ null === form.currentRevision ? { __( 'The form is not published yet. The code shows it once you publish it.', 'funnelforms-pro' ) } : null }
{ body }

{ __( 'Preview', 'funnelforms-pro' ) }

{ sketchText( method, frame ) }
); } /** What Funnelforms Free names for the Pro ways. */ function proItems( method: EmbedMethod ): string[] { switch ( method ) { case 'popup': return [ __( 'Popup after a delay', 'funnelforms-pro' ), __( 'Popup on a click', 'funnelforms-pro' ), __( 'Popup after scrolling', 'funnelforms-pro' ), __( 'Popup when the visitor is about to leave', 'funnelforms-pro' ) ]; case 'widget': return [ __( 'Button in a corner of the page', 'funnelforms-pro' ), __( 'Text, colour and animation of the button', 'funnelforms-pro' ) ]; default: return [ __( 'Embed code for websites outside WordPress', 'funnelforms-pro' ), __( 'Width, height and automatic height', 'funnelforms-pro' ) ]; } } function sketchText( method: EmbedMethod, frame: FrameSettings ): string { switch ( method ) { case 'inline': return __( 'The form takes the width of the content area and grows with each step.', 'funnelforms-pro' ); case 'link': return __( 'The form alone on a page, without the menu and footer of your theme.', 'funnelforms-pro' ); case 'popup': return __( 'The form opens above the page; visitors close it with the cross or the Escape key.', 'funnelforms-pro' ); case 'widget': return __( 'The button stays in its corner while visitors scroll; a click opens the form.', 'funnelforms-pro' ); default: return frame.autoHeight ? __( 'The frame grows and shrinks with each step of the form.', 'funnelforms-pro' ) : __( 'The frame keeps its height; longer steps scroll inside it.', 'funnelforms-pro' ); } } /* ------------------------------------------------------------------ inline */ function InlinePanel() { const form = useBuilder( ( s ) => s.form ); const [ target, setTarget ] = useState( 'shortcode' ); if ( ! form ) { return null; } const targets: Array<[ InlineTarget, string ]> = [ [ 'shortcode', __( 'Shortcode', 'funnelforms-pro' ) ], [ 'block', __( 'Block editor', 'funnelforms-pro' ) ], [ 'elementor', 'Elementor' ], ]; const steps: Record = { shortcode: [ __( 'Copy the shortcode.', 'funnelforms-pro' ), __( 'Open the page or post in WordPress where the form should appear.', 'funnelforms-pro' ), __( 'Paste the shortcode there, in the block editor into a Shortcode block.', 'funnelforms-pro' ), __( 'Save the page. The form appears in its place.', 'funnelforms-pro' ), ], block: [ __( 'Open the page or post in the block editor.', 'funnelforms-pro' ), __( 'Add the block "Funnelforms" where the form should appear.', 'funnelforms-pro' ), sprintf( __( 'Choose "%s" in the settings of the block.', 'funnelforms-pro' ), form.title ), 'free' === process.env.FUNNELFORMS_EDITION ? __( 'Save the page. The form appears in its place.', 'funnelforms-pro' ) : __( 'Save the page. Under Display the block also shows the form as a popup or a button.', 'funnelforms-pro' ), ], elementor: [ __( 'Open the page with Elementor.', 'funnelforms-pro' ), __( 'Drag the widget "Funnelforms" to where the form should appear.', 'funnelforms-pro' ), sprintf( __( 'Choose "%s" in the settings of the widget.', 'funnelforms-pro' ), form.title ), 'free' === process.env.FUNNELFORMS_EDITION ? __( 'Save the page. The form appears in its place.', 'funnelforms-pro' ) : __( 'Publish the page. Under Display the widget also shows the form as a popup or a button.', 'funnelforms-pro' ), ], }; return ( <>
{ targets.map( ( [ id, label ] ) => ( ) ) }

{ __( 'The shortcode works in every editor, also in widgets and theme builders.', 'funnelforms-pro' ) }

); } /* ------------------------------------------------------------------ direct link */ function LinkPanel() { const { api, store, readOnly } = useEnv(); const form = useBuilder( ( s ) => s.form ); const saved = form?.publicSlug ?? ''; const [ slug, setSlug ] = useState( saved ); const [ busy, setBusy ] = useState( false ); const [ error, setError ] = useState( null ); useEffect( () => setSlug( saved ), [ saved ] ); if ( ! form ) { return null; } const cleaned = cleanSlug( slug ); const save = async (): Promise => { setBusy( true ); setError( null ); try { const detail = await api.update( form.id, { publicSlug: cleaned } ); const latest = store.getState().form; if ( latest ) { store.setState( { form: { ...latest, publicSlug: detail.publicSlug ?? '', publicUrl: detail.publicUrl ?? null, publicFallback: detail.publicFallback ?? null } } ); } } catch ( e ) { setError( e instanceof Error ? e.message : String( e ) ); } setBusy( false ); }; return ( <>
{ error ? { error } : null }
{ form.publicUrl ? ( <>

{ __( 'Open the page', 'funnelforms-pro' ) }

) : (

{ __( 'Choose an address for the page first; the link appears here.', 'funnelforms-pro' ) }

) } ); } /* ------------------------------------------------------------------ sketch */ /** A small browser window that shows where the form appears. */ export function EmbedSketch( { method, widget, frame, url }: { method: EmbedMethod; widget: WidgetSettings; frame: FrameSettings; url: string } ) { const corner = 'widget' === method ? widget.position : 'bottom-right'; const page = 'link' !== method; return ( ); } function SketchForm() { return (
); }