| 1 |
import { useEffect, useMemo } from "@wordpress/element"; |
| 2 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 3 |
import InspectorControl from "../../components/inspectorControls/inspectorControls"; |
| 4 |
import { panelBodyRightIcon, panelBodyTitleIcon } from "../../icons/icons"; |
| 5 |
import dynamicCssFn from "./dynamicCss"; |
| 6 |
import Inspector from "./inspector"; |
| 7 |
import { TogglePanelBodyProvider } from "../../context"; |
| 8 |
import TocRender from "./RenderToc"; |
| 9 |
import { compose } from "@wordpress/compose"; |
| 10 |
import addInitialAttr from "../shared/addInitialAttr"; |
| 11 |
import { jsonStringify } from "../shared/helpFn"; |
| 12 |
import { googleFonts } from "../../controls/controls"; |
| 13 |
const TableOfContent = (props) => { |
| 14 |
const { attributes, setAttributes } = props; |
| 15 |
const { |
| 16 |
blockName, |
| 17 |
uniqueId, |
| 18 |
fontListsEditPage, |
| 19 |
additionalCssClass, |
| 20 |
customCss, |
| 21 |
contentTypography, |
| 22 |
headingTypography, |
| 23 |
listTypography, |
| 24 |
collapseTypography, |
| 25 |
} = attributes; |
| 26 |
const blockStyling = useMemo(() => dynamicCssFn(attributes), [attributes]); |
| 27 |
|
| 28 |
const googleFontLists = [contentTypography, headingTypography, listTypography, collapseTypography]; |
| 29 |
|
| 30 |
const googleFontListsEditor = useMemo(() => googleFonts(googleFontLists), googleFontLists); |
| 31 |
|
| 32 |
useEffect(() => { |
| 33 |
setAttributes({ |
| 34 |
fontLists: jsonStringify(googleFonts(googleFontLists, "frontend")), |
| 35 |
fontListsEditPage: googleFontListsEditor, |
| 36 |
}); |
| 37 |
}, googleFontLists); |
| 38 |
|
| 39 |
const blockProps = useBlockProps(); |
| 40 |
return ( |
| 41 |
<div {...blockProps}> |
| 42 |
<style> |
| 43 |
{fontListsEditPage} |
| 44 |
{blockStyling} |
| 45 |
{customCss} |
| 46 |
</style> |
| 47 |
<TogglePanelBodyProvider blockName={blockName}> |
| 48 |
<InspectorControl |
| 49 |
TitleIcon={panelBodyTitleIcon} |
| 50 |
RightIcon={panelBodyRightIcon} |
| 51 |
Inspector={Inspector} |
| 52 |
attributes={attributes} |
| 53 |
setAttributes={setAttributes} |
| 54 |
/> |
| 55 |
|
| 56 |
<div |
| 57 |
id={uniqueId} |
| 58 |
className={`sp-table-of-content-toc ${additionalCssClass ? additionalCssClass : ""}`} |
| 59 |
> |
| 60 |
<TocRender setAttributes={setAttributes} attributes={attributes} /> |
| 61 |
</div> |
| 62 |
</TogglePanelBodyProvider> |
| 63 |
</div> |
| 64 |
); |
| 65 |
}; |
| 66 |
|
| 67 |
export default compose(addInitialAttr)(TableOfContent); |
| 68 |
|