Server IP : 103.119.228.120 / Your IP : 3.146.206.246 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/softaculous/sitepad/editor/site-data/plugins/pagelayer/js/react/src/components/ |
Upload File : |
import { BlockControls, RichText, } from '@wordpress/block-editor'; import { ToolbarGroup, DropdownMenu, Icon } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { useEffect, useState, useRef } from '@wordpress/element'; import { headingLevel1, headingLevel2, headingLevel3, headingLevel4, headingLevel5, headingLevel6, paragraph, } from '@wordpress/icons'; // This control use to create richtext area in editor export const RichTextControl = (props) =>{ const { _props, propsName, value, tagName : TagName } = props; const { setAttributes, attributes } = _props; const [headingLevel, setHeadingLevel] = useState(null); const richRef = useRef(null); var newProps = { ...props }; var renderVal = pagelayerTrim(value); if(renderVal == `{{${propsName}}}`){ renderVal = ''; } delete newProps._props; delete newProps.propsName; delete newProps.value; delete newProps['pagelayer-editable']; const tagNames = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; // Make child editable if child is single and wrapped by block tag var children = jQuery(`<div>${value}</div>`)[0].childNodes; var childTag = null; if( children.length == 1 && children[0].nodeType != 3 && tagNames.indexOf(children[0].localName) != -1 ){ childTag = children[0].localName; delete newProps.tagName; } // Save the rich text data with tag const HeadingFormatting = (value) => { if(headingLevel == null) return; var newTag = tagNames[headingLevel]; var newVal = `<${newTag}>${value}</${newTag}>`; if(children[0].attributes.length > 0){ newVal = `<${newTag} ${children[0].attributes}>${value}</${newTag}>`; } setAttributes({ [propsName]: newVal }); } useEffect( () => { //HeadingFormatting if (richRef.current) { richRef.current.dispatchEvent(new Event('input', { bubbles: true })); } }, [headingLevel]); useEffect(() => { if(children.length < 1){ return; } setHeadingLevel( tagNames.indexOf(children[0].localName) ); }, []); return ( <> { childTag ? ( <> <BlockControls group="block"> <HeadingLevelDropdown options={ [ 1, 2, 3, 4, 5, 6, 0 ] } value={ headingLevel } onChange={ ( newLevel ) => setHeadingLevel(newLevel) } /> </BlockControls> <TagName {...newProps}> <RichText ref={richRef} key="editable" tagName={childTag} keepPlaceholderOnFocus placeholder={'Add Content...'} onChange={ (value) => HeadingFormatting(value) } value={ children[0].innerHTML} {...children[0].attributes} /> </TagName> </> ) : ( <RichText key="editable" keepPlaceholderOnFocus placeholder={'Add Content...'} onChange={(value) => setAttributes({ [propsName]: value })} value={ pagelayer_empty(attributes[propsName]) ? renderVal : attributes[propsName]} {...newProps} /> )} </> ); } // HeadingLevelDropdown props. const HEADING_LEVELS = [ 1, 2, 3, 4, 5, 6 ]; export function HeadingLevelDropdown( { options = HEADING_LEVELS, value, onChange, } ) { const createLevelControl = ( targetLevel, currentLevel, onChangeCallback ) => { const isActive = targetLevel === currentLevel; return { icon: ( <HeadingLevelIcon level={ targetLevel } isPressed={ isActive } /> ), // translators: %s: heading level e.g: "1", "2", "3" // title: sprintf( __( 'Heading %d' ), targetLevel ), isActive, onClick: () => onChangeCallback( targetLevel ), }; }; return ( <DropdownMenu icon={ <HeadingLevelIcon level={ value } /> } controls={ options.map( ( index ) => createLevelControl( index, value, onChange ) ) } label={ __( 'Change level' ) } /> ); } // HeadingLevelIcon props. const LEVEL_TO_PATH = { 0: paragraph, 1: headingLevel1, 2: headingLevel2, 3: headingLevel3, 4: headingLevel4, 5: headingLevel5, 6: headingLevel6, }; export function HeadingLevelIcon( { level } ) { if ( LEVEL_TO_PATH[ level ] ) { return <Icon icon={ LEVEL_TO_PATH[ level ] } />; } return null; }