| 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.10/wp-content/themes/blocksy/static/js/options/options/ |
Upload File : |
import { Fragment, createElement, Component } from '@wordpress/element'
import OptionsPanel from '../OptionsPanel'
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'
import { reorder } from '../options/ct-layers'
import { nanoid } from 'nanoid'
import { getValueFromInput } from '../helpers/get-value-from-input'
const valueWithUniqueIds = (value) =>
value.map((singleItem) => ({
...singleItem,
...(singleItem.__id
? {}
: {
__id: nanoid(),
}),
}))
const LayersCombined = ({ option, value, onChange }) => {
let computedValue = Object.keys(value).reduce((acc, key) => {
return {
...acc,
[key]: valueWithUniqueIds(value[key]),
}
}, {})
const fullValue = Object.values(computedValue).reduce(
(acc, value) => [...acc, ...value],
[]
)
const defaultValue = Object.values(
getValueFromInput(option['inner-options'], {})
).reduce((acc, value) => [...acc, ...value])
const missingItemsForRightColumn = valueWithUniqueIds([
...defaultValue.filter(
({ id }) => !fullValue.find(({ id: id2 }) => id === id2)
),
])
computedValue.right = [
...computedValue.right,
...missingItemsForRightColumn,
]
return (
<DragDropContext
onDragEnd={(result) => {
if (!result.destination) {
return
}
if (
result.destination.droppableId === result.source.droppableId
) {
onChange({
...computedValue,
[result.destination.droppableId]: reorder(
computedValue[result.destination.droppableId],
result.source.index,
result.destination.index
),
})
return
}
const current = computedValue[result.source.droppableId]
const next = computedValue[result.destination.droppableId]
const target = current[result.source.index]
current.splice(result.source.index, 1)
next.splice(result.destination.index, 0, target)
onChange({
...computedValue,
[result.source.droppableId]: current,
[result.destination.droppableId]: next,
})
}}>
<OptionsPanel
onChange={(key, optionValue) => {
onChange({
...computedValue,
[key]: optionValue,
})
}}
options={option['inner-options']}
value={computedValue}
/>
</DragDropContext>
)
}
export default LayersCombined