__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import {
createElement,
Component,
createContext,
useState,
Fragment,
useMemo,
} from '@wordpress/element'
import classnames from 'classnames'
import { normalizeCondition, matchValuesWithCondition } from 'match-conditions'
import arrayMove from 'array-move'
import { getValueFromInput } from '../helpers/get-value-from-input'
import nanoid from 'nanoid'
import SelectThatAddsItems from './ct-layers/SelectThatAddsItems'
import SingleItem from './ct-layers/SingleItem'
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'
export const reorder = (list, startIndex, endIndex) => {
const result = Array.from(list)
const [removed] = result.splice(startIndex, 1)
result.splice(endIndex, 0, removed)
return result
}
const valueWithUniqueIds = (value) =>
value
.filter((singleItem) => singleItem)
.map((singleItem) => ({
...singleItem,
...(singleItem.__id
? {}
: {
__id: nanoid(),
}),
}))
export const itemsThatAreNotAdded = (value, option) =>
Object.keys(option.settings).filter(
(optionId) => !value.find(({ id }) => id === optionId)
)
const getDefaultState = () => ({
currentlyPickedItem: null,
isDragging: false,
isOpen: false,
})
export const LayersContext = createContext(getDefaultState())
const { Provider, Consumer } = LayersContext
const Layers = ({ value, option, onChange, values }) => {
const [state, setState] = useState(getDefaultState())
const addForId = (idToAdd, val = {}) => {
onChange([
...(value || []),
{
id: idToAdd,
enabled: true,
...getValueFromInput(
option.settings[idToAdd].options || {},
{}
),
...val,
__id: nanoid(),
},
])
}
const computedValue = (
option.manageable || option.grouped
? valueWithUniqueIds(value)
: [
...valueWithUniqueIds(value),
...option.value
.filter(
({ id }) =>
value.map(({ id }) => id).indexOf(id) === -1
)
.map((item) => ({
...item,
__id: nanoid(),
enabled: item?.enabled || false,
})),
]
).filter((item) => !!option.settings[item.id])
let withoutDragDropContext = (
<Provider
value={{
...state,
parentValue: values,
addCurrentlySelectedItem: () => {
const idToAdd =
state.currentlyPickedItem ||
itemsThatAreNotAdded(
valueWithUniqueIds(value),
option
)[0]
setState((state) => ({
...state,
currentlyPickedItem: null,
}))
addForId(idToAdd)
},
addForId: (id, value) => addForId(id, value),
option: option,
setCurrentItem: (currentlyPickedItem) =>
setState((state) => ({
...state,
currentlyPickedItem,
})),
removeForId: (idToRemove) =>
onChange(
valueWithUniqueIds(value).filter(
({ __id: id }) => id !== idToRemove
)
),
toggleOptionsPanel: (idToAdd) => {
const completeValue = [
...value,
...option.value.filter(
({ id }) =>
value.map(({ id }) => id).indexOf(id) === -1
),
]
if (
value.length > 0 &&
completeValue.find((item) => !item.__id)
) {
wp.customize &&
wp.customize.previewer &&
wp.customize.previewer.send(
'ct:sync:refresh_partial',
{
shouldSkip: true,
}
)
onChange(computedValue)
}
setState((state) => ({
...state,
isOpen: state.isOpen === idToAdd ? false : idToAdd,
}))
},
}}>
{option.manageable && (
<SelectThatAddsItems
{...{
value: computedValue,
option,
}}
/>
)}
<Droppable droppableId={option.id}>
{(provided, snapshot) => (
<ul
className={classnames(
'ct-layers',
(option.attr || {}).class
)}
{...provided.droppableProps}
ref={provided.innerRef}>
{computedValue.map((value, index) => {
const { condition, values_source } =
option.settings[value.id]
let valueForCondition = values
if (values_source === 'global') {
valueForCondition = Object.keys(
condition
).reduce(
(current, key) => ({
...current,
[key.split(':')[0]]: wp.customize(
key.split(':')[0]
)(),
}),
{}
)
}
return (
<Draggable
key={value.__id}
draggableId={value.__id}
isDragDisabled={!!option.disableDrag}
index={index}>
{(provided, snapshot) => {
return (
<SingleItem
onChange={onChange}
value={value}
items={computedValue}
provided={provided}
snapshot={snapshot}
className={
condition &&
!matchValuesWithCondition(
normalizeCondition(
condition
),
valueForCondition
)
? 'ct-hidden'
: ''
}
/>
)
}}
</Draggable>
)
})}
{provided.placeholder}
</ul>
)}
</Droppable>
</Provider>
)
if (option.grouped) {
return withoutDragDropContext
}
return (
<DragDropContext
onDragEnd={(result) => {
if (!result.destination) {
return
}
onChange(
reorder(
computedValue,
result.source.index,
result.destination.index
)
)
}}>
{withoutDragDropContext}
</DragDropContext>
)
}
export default Layers
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| background | Folder | 0750 |
|
|
| box-shadow | Folder | 0750 |
|
|
| color-palettes | Folder | 0750 |
|
|
| color-picker | Folder | 0750 |
|
|
| ct-addable-box | Folder | 0750 |
|
|
| ct-layers | Folder | 0750 |
|
|
| ct-number | Folder | 0750 |
|
|
| ct-radio | Folder | 0750 |
|
|
| ct-select | Folder | 0750 |
|
|
| ct-slider | Folder | 0750 |
|
|
| ct-spacing | Folder | 0750 |
|
|
| ct-switch | Folder | 0750 |
|
|
| ratio | Folder | 0750 |
|
|
| text | Folder | 0750 |
|
|
| typography | Folder | 0750 |
|
|
| ct-addable-box.js | File | 6.16 KB | 0640 |
|
| ct-background.js | File | 5.46 KB | 0640 |
|
| ct-border.js | File | 2.75 KB | 0640 |
|
| ct-box-shadow.js | File | 2.64 KB | 0640 |
|
| ct-button.js | File | 456 B | 0640 |
|
| ct-checkboxes.js | File | 1.91 KB | 0640 |
|
| ct-color-palettes-mirror.js | File | 1000 B | 0640 |
|
| ct-color-palettes-picker.js | File | 6.71 KB | 0640 |
|
| ct-color-picker.js | File | 2.71 KB | 0640 |
|
| ct-customize-section-title-actions.js | File | 6.74 KB | 0640 |
|
| ct-customizer-reset-options.js | File | 1.83 KB | 0640 |
|
| ct-divider.js | File | 328 B | 0640 |
|
| ct-entity-picker.js | File | 2.38 KB | 0640 |
|
| ct-file-uploader.js | File | 2 KB | 0640 |
|
| ct-footer-builder.js | File | 5.96 KB | 0640 |
|
| ct-header-builder.js | File | 272 B | 0640 |
|
| ct-image-picker.js | File | 1.81 KB | 0640 |
|
| ct-image-uploader.js | File | 10.12 KB | 0640 |
|
| ct-layers-combined.js | File | 2.22 KB | 0640 |
|
| ct-layers-mirror.js | File | 1.15 KB | 0640 |
|
| ct-layers.js | File | 5.39 KB | 0640 |
|
| ct-multi-image-uploader.js | File | 3.14 KB | 0640 |
|
| ct-notification.js | File | 378 B | 0640 |
|
| ct-number.js | File | 454 B | 0640 |
|
| ct-panel.js | File | 8.88 KB | 0640 |
|
| ct-radio.js | File | 401 B | 0640 |
|
| ct-ratio.js | File | 6.87 KB | 0640 |
|
| ct-select.js | File | 669 B | 0640 |
|
| ct-slider.js | File | 14.14 KB | 0640 |
|
| ct-spacer.js | File | 386 B | 0640 |
|
| ct-spacing.js | File | 5.09 KB | 0640 |
|
| ct-switch.js | File | 508 B | 0640 |
|
| ct-timer.js | File | 3.27 KB | 0640 |
|
| ct-title.js | File | 562 B | 0640 |
|
| ct-typography.js | File | 7.35 KB | 0640 |
|
| ct-visibility.js | File | 4.76 KB | 0640 |
|
| ct-woocommerce-columns-and-rows.js | File | 3 KB | 0640 |
|
| ct-woocommerce-ratio.js | File | 1.66 KB | 0640 |
|
| date-time-picker.js | File | 811 B | 0640 |
|
| hidden.js | File | 243 B | 0640 |
|
| html.js | File | 264 B | 0640 |
|
| jsx.js | File | 237 B | 0640 |
|
| react-outside-click-handler.js | File | 3.17 KB | 0640 |
|
| text.js | File | 384 B | 0640 |
|
| textarea.js | File | 518 B | 0640 |
|
| wp-editor.js | File | 3.67 KB | 0640 |
|