PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.7
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / blocks / table-of-content / edit.js

edit.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at src/blocks/table-of-content/edit.js

68 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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