| Server IP : 38.190.208.107 / Your IP : 216.73.217.51 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/themes/blocksy/static/js/options/options/ |
Upload File : |
import {
createElement,
createPortal,
useContext,
Fragment,
useState,
Component,
useRef,
} from '@wordpress/element'
import { maybeTransformUnorderedChoices } from '../helpers/parse-choices.js'
import classnames from 'classnames'
import { Transition, animated } from 'react-spring'
import bezierEasing from 'bezier-easing'
import OutsideClickHandler from './react-outside-click-handler'
import { __ } from 'ct-i18n'
const InlineVisibility = ({ option, value, onChange }) => {
return (
<ul
className="ct-visibility-option ct-devices ct-buttons-group"
{...(option.attr || {})}>
{maybeTransformUnorderedChoices(option.choices).map(
({ key, value: val }) => (
<li
className={classnames(
{
active: value[key],
},
`ct-${key}`
)}
onClick={() =>
onChange({
...value,
[key]: value[key]
? Object.values(value).filter((v) => v)
.length === 1 && !option.allow_empty
? true
: false
: true,
})
}
key={key}
/>
)
)}
</ul>
)
}
const VisibilityModal = ({ option, value, onChange }) => {
const [{ isPicking, isTransitioning }, setAnimationState] = useState({
isPicking: null,
isTransitioning: null,
})
const stopTransitioning = () =>
setAnimationState({
isPicking,
isTransitioning: false,
})
const el = useRef()
return (
<Fragment>
<OutsideClickHandler
useCapture={false}
disabled={!isPicking}
className="ct-visibility-trigger"
additionalRefs={[]}
onOutsideClick={() => {
if (!isPicking) {
return
}
setAnimationState({
isTransitioning: true,
isPicking: null,
})
}}
wrapperProps={{
ref: el,
onClick: (e) => {
e.preventDefault()
setAnimationState({
isTransitioning: true,
isPicking: true,
})
},
}}>
<span>open visibility</span>
</OutsideClickHandler>
{(isTransitioning || isPicking) &&
createPortal(
<Transition
items={isPicking}
onRest={(isOpen) => {
stopTransitioning()
}}
config={{
duration: 100,
easing: bezierEasing(0.25, 0.1, 0.25, 1.0),
}}
from={
isPicking
? {
transform: 'scale3d(0.95, 0.95, 1)',
opacity: 0,
}
: { opacity: 1 }
}
enter={
isPicking
? {
transform: 'scale3d(1, 1, 1)',
opacity: 1,
}
: {
opacity: 1,
}
}
leave={
isPicking
? {
transform: 'scale3d(0.95, 0.95, 1)',
opacity: 0,
}
: {
opacity: 1,
}
}>
{(props, isPicking) =>
isPicking && (
<animated.div
style={props}
className="ct-box-shadow-modal"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
}}
onMouseDownCapture={(e) => {
e.nativeEvent.stopImmediatePropagation()
e.nativeEvent.stopPropagation()
}}
onMouseUpCapture={(e) => {
e.nativeEvent.stopImmediatePropagation()
e.nativeEvent.stopPropagation()
}}>
<InlineVisibility
option={option}
value={value}
onChange={onChange}
/>
</animated.div>
)
}
</Transition>,
el.current.closest('.ct-labeled-group-item')
? el.current
.closest('.ct-labeled-group-item')
.querySelector('.ct-visibility-modal-wrapper')
: el.current.closest('.ct-single-palette')
? el.current
.closest('.ct-single-palette')
.querySelector('.ct-visibility-modal-wrapper')
: el.current.closest('.ct-visibility-modal-wrapper')
? el.current.closest('.ct-visibility-modal-wrapper')
: el.current
.closest('.ct-control')
.querySelector('.ct-visibility-modal-wrapper')
)}
</Fragment>
)
}
const Visibility = ({
option,
option: {
// inline | modal
view = 'inline',
},
value,
onChange,
}) => {
if (view === 'inline') {
return (
<InlineVisibility
option={option}
value={value}
onChange={onChange}
/>
)
}
return <VisibilityModal option={option} value={value} onChange={onChange} />
}
Visibility.hiddenResponsive = true
Visibility.ControlEnd = () => <div className="ct-visibility-modal-wrapper" />
Visibility.renderingConfig = {
getValueForRevert: ({ value }) => {
if (typeof value === 'object') {
if (
value.desktop &&
value.desktop === value.tablet &&
value.tablet === value.mobile
) {
return true
}
if (
!value.desktop &&
value.desktop === value.tablet &&
value.tablet === value.mobile
) {
return false
}
}
return value
},
}
export default Visibility