| 1 |
import { useEffect, useMemo } from "@wordpress/element"; |
| 2 |
import { jsonStringify } from "../shared/helpFn"; |
| 3 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 4 |
import { InspectorControl } from "../../components"; |
| 5 |
import Inspector from "./inspect"; |
| 6 |
import { TogglePanelBodyProvider } from "../../context"; |
| 7 |
import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons"; |
| 8 |
import Render from "./Render"; |
| 9 |
import dynamicCssFn from "./dynamicCss"; |
| 10 |
import { googleFonts, useDeviceType } from "../../controls/controls"; |
| 11 |
import { compose } from "@wordpress/compose"; |
| 12 |
import addInitialAttr from "../shared/addInitialAttr"; |
| 13 |
const TaxonomyEdit = ({ attributes, setAttributes }) => { |
| 14 |
const currentDevice = useDeviceType(); |
| 15 |
const blockProps = useBlockProps(); |
| 16 |
const { blockName, uniqueId, additionalCssClass, equalHeightEnable, titleTypography, fontListsEditPage } = |
| 17 |
attributes; |
| 18 |
|
| 19 |
const blockStyling = useMemo( |
| 20 |
() => dynamicCssFn(attributes, "frontend", currentDevice), |
| 21 |
[attributes, currentDevice] |
| 22 |
); |
| 23 |
|
| 24 |
const googleFontLists = [titleTypography]; |
| 25 |
|
| 26 |
useEffect(() => { |
| 27 |
setAttributes({ |
| 28 |
fontLists: jsonStringify(googleFonts(googleFontLists, "frontend")), |
| 29 |
fontListsEditPage: googleFonts(googleFontLists), |
| 30 |
}); |
| 31 |
}, googleFontLists); |
| 32 |
|
| 33 |
return ( |
| 34 |
<div {...blockProps}> |
| 35 |
<style> |
| 36 |
{fontListsEditPage} |
| 37 |
{blockStyling} |
| 38 |
</style> |
| 39 |
<TogglePanelBodyProvider> |
| 40 |
<InspectorControl |
| 41 |
TitleIcon={panelBodyTitleIcon} |
| 42 |
RightIcon={panelBodyRightIcon} |
| 43 |
attributes={attributes} |
| 44 |
setAttributes={setAttributes} |
| 45 |
Inspector={Inspector} |
| 46 |
/> |
| 47 |
|
| 48 |
<div |
| 49 |
id={uniqueId} |
| 50 |
className={`sp-smart-post-wrapper ${additionalCssClass} sp-smart-${blockName}-editor-page sp-smart-post-${blockName} ${ |
| 51 |
equalHeightEnable ? "sp-smart-post-show-equal-height" : "" |
| 52 |
}`} |
| 53 |
> |
| 54 |
<Render attributes={attributes} /> |
| 55 |
</div> |
| 56 |
</TogglePanelBodyProvider> |
| 57 |
</div> |
| 58 |
); |
| 59 |
}; |
| 60 |
|
| 61 |
export default compose(addInitialAttr)(TaxonomyEdit); |
| 62 |
|