| 1 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 2 |
import { InspectorControl } from "../../components"; |
| 3 |
import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons"; |
| 4 |
import Render from "./render"; |
| 5 |
import dynamicCss from "./dynamicCss"; |
| 6 |
import { Inspector } from "./inspector"; |
| 7 |
import { TogglePanelBodyProvider } from "../../context"; |
| 8 |
import { useEffect, useMemo } from "@wordpress/element"; |
| 9 |
import classNames from "classnames"; |
| 10 |
import { googleFonts } from "../../controls/controls"; |
| 11 |
import { select } from "@wordpress/data"; |
| 12 |
import { compose } from "@wordpress/compose"; |
| 13 |
import addInitialAttr from "../shared/addInitialAttr"; |
| 14 |
import { jsonStringify, ProTopBar } from "../shared/helpFn"; |
| 15 |
|
| 16 |
const SmartSearchEdit = ({ attributes, setAttributes }) => { |
| 17 |
const blockProps = useBlockProps(); |
| 18 |
const { |
| 19 |
blockName, |
| 20 |
uniqueId, |
| 21 |
additionalCssClass, |
| 22 |
fontListsEditPage, |
| 23 |
inputPlaceholderTypography, |
| 24 |
inputPlaceHolderGlobalTypography, |
| 25 |
searchBtnLabelTypography, |
| 26 |
searchResultTitleTypography, |
| 27 |
searchResultMetaTypography, |
| 28 |
searchResultTitleGlobalTypography, |
| 29 |
searchResultMetaGlobalTypography, |
| 30 |
moreResultTypography, |
| 31 |
moreResultGlobalTypography, |
| 32 |
popupHeadingTypography, |
| 33 |
popupHeadingGlobalTypography, |
| 34 |
} = attributes; |
| 35 |
|
| 36 |
// set typography. |
| 37 |
const googleFontLists = [ |
| 38 |
inputPlaceholderTypography, |
| 39 |
inputPlaceHolderGlobalTypography, |
| 40 |
searchBtnLabelTypography, |
| 41 |
searchResultTitleTypography, |
| 42 |
searchResultMetaTypography, |
| 43 |
searchResultTitleGlobalTypography, |
| 44 |
searchResultMetaGlobalTypography, |
| 45 |
moreResultTypography, |
| 46 |
moreResultGlobalTypography, |
| 47 |
popupHeadingTypography, |
| 48 |
popupHeadingGlobalTypography, |
| 49 |
]; |
| 50 |
useEffect(() => { |
| 51 |
setAttributes({ |
| 52 |
fontLists: jsonStringify(googleFonts(googleFontLists, "frontend")), |
| 53 |
fontListsEditPage: googleFonts(googleFontLists, "edit"), |
| 54 |
}); |
| 55 |
}, googleFontLists); |
| 56 |
|
| 57 |
// set breakpoint |
| 58 |
const getGlobalBreakpoint = select("smartpost/global-settings").getCategory("breakpoint"); |
| 59 |
useEffect(() => { |
| 60 |
if (typeof getGlobalBreakpoint === "object") { |
| 61 |
setAttributes({ globalBreakPointData: getGlobalBreakpoint }); |
| 62 |
} |
| 63 |
}, [getGlobalBreakpoint]); |
| 64 |
|
| 65 |
const blockStyling = useMemo(() => dynamicCss(attributes, "frontend"), [attributes]); |
| 66 |
return ( |
| 67 |
<div {...blockProps}> |
| 68 |
<style>{blockStyling}</style> |
| 69 |
<style>{fontListsEditPage}</style> |
| 70 |
<TogglePanelBodyProvider> |
| 71 |
<InspectorControl |
| 72 |
TitleIcon={panelBodyTitleIcon} |
| 73 |
RightIcon={panelBodyRightIcon} |
| 74 |
attributes={attributes} |
| 75 |
setAttributes={setAttributes} |
| 76 |
Inspector={Inspector} |
| 77 |
/> |
| 78 |
|
| 79 |
<div id={uniqueId} className={classNames("sp-smart-post-wrapper", additionalCssClass)}> |
| 80 |
<ProTopBar |
| 81 |
blockName={blockName} |
| 82 |
title="Smart Search" |
| 83 |
/> |
| 84 |
<Render attributes={attributes} setAttributes={setAttributes} /> |
| 85 |
</div> |
| 86 |
</TogglePanelBodyProvider> |
| 87 |
</div> |
| 88 |
); |
| 89 |
}; |
| 90 |
|
| 91 |
export default compose(addInitialAttr)(SmartSearchEdit); |
| 92 |
|