| 1 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 2 |
import { useEffect, useState, useMemo } from "@wordpress/element"; |
| 3 |
import InspectorControl from "../../components/inspectorControls/inspectorControls"; |
| 4 |
import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons"; |
| 5 |
import { EditorWrapper } from "../shared/wrapper"; |
| 6 |
import dynamicCssFn from "./dynamicCss"; |
| 7 |
import Inspector from "./inspect"; |
| 8 |
import Render from "./render"; |
| 9 |
import { useDeviceType } from "../../controls/controls"; |
| 10 |
import { TogglePanelBodyProvider } from "../../context"; |
| 11 |
import { cssDependency } from "../shared/cssDependency"; |
| 12 |
import { compose } from "@wordpress/compose"; |
| 13 |
import addInitialAttr from "../shared/addInitialAttr"; |
| 14 |
|
| 15 |
const TimelineOneEdit = ({ attributes, setAttributes, isSelected }) => { |
| 16 |
const [posts, setPosts] = useState([]); |
| 17 |
const { |
| 18 |
blockName, |
| 19 |
contentAreaBg, |
| 20 |
postCardBg, |
| 21 |
fontListsEditPage, |
| 22 |
gapBetweenPosts, |
| 23 |
imageSpace, |
| 24 |
contentAreaPadding, |
| 25 |
postCardBoxShadow, |
| 26 |
postCardHoverBoxShadow, |
| 27 |
imageHeight, |
| 28 |
customCss, |
| 29 |
} = attributes; |
| 30 |
|
| 31 |
const blockProps = useBlockProps(); |
| 32 |
const deviceType = useDeviceType(); |
| 33 |
|
| 34 |
useEffect(() => { |
| 35 |
if (!blockName) { |
| 36 |
setAttributes({ |
| 37 |
timelineLayout: "timeline-one-layout-one", |
| 38 |
gapBetweenPosts: { |
| 39 |
...gapBetweenPosts, |
| 40 |
device: { ...gapBetweenPosts.device, Desktop: 20 }, |
| 41 |
}, |
| 42 |
contentAreaBg: { |
| 43 |
...contentAreaBg, |
| 44 |
color: { |
| 45 |
...contentAreaBg?.color, |
| 46 |
style: "", |
| 47 |
}, |
| 48 |
hover: { |
| 49 |
...contentAreaBg?.hover, |
| 50 |
style: "", |
| 51 |
}, |
| 52 |
}, |
| 53 |
postCardBg: { |
| 54 |
...postCardBg, |
| 55 |
color: { |
| 56 |
...postCardBg?.color, |
| 57 |
style: "", |
| 58 |
}, |
| 59 |
hover: { |
| 60 |
...postCardBg?.hover, |
| 61 |
style: "", |
| 62 |
}, |
| 63 |
}, |
| 64 |
imageSpace: { |
| 65 |
...imageSpace, |
| 66 |
device: { |
| 67 |
...imageSpace.device, |
| 68 |
Desktop: 16, |
| 69 |
}, |
| 70 |
}, |
| 71 |
contentAreaPadding: { |
| 72 |
...contentAreaPadding, |
| 73 |
device: { |
| 74 |
...contentAreaPadding.device, |
| 75 |
Desktop: { |
| 76 |
...contentAreaPadding.device.Desktop, |
| 77 |
top: "0", |
| 78 |
right: "20", |
| 79 |
bottom: "15", |
| 80 |
left: "20", |
| 81 |
}, |
| 82 |
Tablet: { |
| 83 |
...contentAreaPadding.device.Tablet, |
| 84 |
top: "0", |
| 85 |
right: "20", |
| 86 |
bottom: "15", |
| 87 |
left: "20", |
| 88 |
}, |
| 89 |
}, |
| 90 |
}, |
| 91 |
postCardBoxShadowEnable: true, |
| 92 |
postCardHoverBoxShadowEnable: true, |
| 93 |
postCardBoxShadow: { |
| 94 |
...postCardBoxShadow, |
| 95 |
device: { |
| 96 |
...postCardBoxShadow.device, |
| 97 |
Desktop: { |
| 98 |
top: 0, |
| 99 |
right: 0, |
| 100 |
bottom: 20, |
| 101 |
left: 0, |
| 102 |
}, |
| 103 |
}, |
| 104 |
color: "#0000001A", |
| 105 |
}, |
| 106 |
postCardHoverBoxShadow: { |
| 107 |
...postCardHoverBoxShadow, |
| 108 |
device: { |
| 109 |
...postCardHoverBoxShadow.device, |
| 110 |
Desktop: { |
| 111 |
top: 0, |
| 112 |
right: 0, |
| 113 |
bottom: 20, |
| 114 |
left: 0, |
| 115 |
}, |
| 116 |
}, |
| 117 |
color: "#0000001A", |
| 118 |
}, |
| 119 |
imageSize: "smart-post-landscape", |
| 120 |
imageHeight: { |
| 121 |
...imageHeight, |
| 122 |
device: { |
| 123 |
...imageHeight?.device, |
| 124 |
Desktop: 310, |
| 125 |
Tablet: 210, |
| 126 |
Mobile: 210, |
| 127 |
}, |
| 128 |
}, |
| 129 |
}); |
| 130 |
} |
| 131 |
}, []); |
| 132 |
|
| 133 |
const blockStyling = useMemo( |
| 134 |
() => dynamicCssFn(attributes, "frontend", deviceType), |
| 135 |
[...cssDependency(attributes), deviceType] |
| 136 |
); |
| 137 |
|
| 138 |
useEffect(() => { |
| 139 |
setAttributes({ currentScreen: deviceType }); |
| 140 |
}, [deviceType]); |
| 141 |
|
| 142 |
return ( |
| 143 |
<div {...blockProps}> |
| 144 |
<style> |
| 145 |
{fontListsEditPage} |
| 146 |
{blockStyling} |
| 147 |
{customCss} |
| 148 |
</style> |
| 149 |
<TogglePanelBodyProvider> |
| 150 |
<InspectorControl |
| 151 |
TitleIcon={panelBodyTitleIcon} |
| 152 |
RightIcon={panelBodyRightIcon} |
| 153 |
Inspector={Inspector} |
| 154 |
attributes={attributes} |
| 155 |
setAttributes={setAttributes} |
| 156 |
isSelected={isSelected} |
| 157 |
/> |
| 158 |
{/* Render Html here */} |
| 159 |
<EditorWrapper setPosts={setPosts} setAttributes={setAttributes}> |
| 160 |
<Render posts={posts} attributes={attributes} page={"editor"} /> |
| 161 |
</EditorWrapper> |
| 162 |
</TogglePanelBodyProvider> |
| 163 |
</div> |
| 164 |
); |
| 165 |
}; |
| 166 |
|
| 167 |
export default compose(addInitialAttr)(TimelineOneEdit); |
| 168 |
|