| 1 |
// Import dynamic CSS generators |
| 2 |
import sectionHeadingDynamicCSS from "../section-heading/dynamicCss"; |
| 3 |
import postCarouselDynamicCSS from "../post-carousel/dynamicCss"; |
| 4 |
import postSliderDynamicCSS from "../post-slider/dynamicCss"; |
| 5 |
import postSliderTwoDynamicCSS from "../post-slider-two/dynamicCss"; |
| 6 |
import postThumbnailDynamicCSS from "../thumbnail-slider/dynamicCss"; |
| 7 |
import postThumbnailTwoDynamicCSS from "../thumbnail-slider-two/dynamicCss"; |
| 8 |
import gridOneDynamicCSS from "../post-grid-one/dynamicCss"; |
| 9 |
import gridTwoDynamicCSS from "../post-grid-two/dynamicCss"; |
| 10 |
import gridThreeDynamicCSS from "../post-grid-three/dynamicCss"; |
| 11 |
import gridFourDynamicCSS from "../post-grid-four/dynamicCss"; |
| 12 |
import gridFiveDynamicCSS from "../post-grid-five/dynamicCss"; |
| 13 |
import gridSixDynamicCSS from "../post-grid-six/dynamicCss"; |
| 14 |
import listOneDynamicCSS from "../post-list-one/dynamicCss"; |
| 15 |
import listTwoDynamicCSS from "../post-list-two/dynamicCss"; |
| 16 |
import listThreeDynamicCSS from "../post-list-three/dynamicCss"; |
| 17 |
import timelineOneDynamicCSS from "../post-timeline-one/dynamicCss"; |
| 18 |
import timelineTwoDynamicCSS from "../post-timeline-two/dynamicCss"; |
| 19 |
import timelineThreeDynamicCSS from "../post-timeline-three/dynamicCss"; |
| 20 |
import containerDynamicCSS from "../container/dynamicCss"; |
| 21 |
import columnDynamicCSS from "../column/dynamicCss"; |
| 22 |
import socialProfilesDynamicCSS from "../social-profiles/dynamicCss"; |
| 23 |
import socialItemDynamicCSS from "../social-profile-item/dynamicCss"; |
| 24 |
import paginationDynamicCSS from "../pagination/dynamicCss"; |
| 25 |
import buttonsDynamicCSS from "../buttons/dynamicCss"; |
| 26 |
import buttonDynamicCSS from "../button/dynamicCss"; |
| 27 |
import taxonomyFilterDynamicCSS from "../taxonomy-filter/dynamicCss"; |
| 28 |
import authorFilterDynamicCSS from "../author-filter/dynamicCss"; |
| 29 |
import liveFilterDynamicCSS from "../live-filter/dynamicCss"; |
| 30 |
import smartSearchDynamicCss from "../smart-search/dynamicCss"; |
| 31 |
import taxonomyDynamicCSS from "../taxonomy/dynamicCss"; |
| 32 |
import NewsDynamicCssFn from "../news-ticker/dynamicCss"; |
| 33 |
import smartImageDynamicCSS from "../smart-image/dynamicCss"; |
| 34 |
import TocDynamicCss from "../table-of-content/dynamicCss"; |
| 35 |
import CarouselTwoDynamicCss from "../post-carousel-two/dynamicCss"; |
| 36 |
import smartInfoBoxDynamicCss from "../smart-info-box/dynamicCss"; |
| 37 |
import ListsDynamicCssFn from "../smart-lists/dynamicCss"; |
| 38 |
import ListDynamicCssFn from "../smart-list/dynamicCss"; |
| 39 |
|
| 40 |
// Create a block CSS generator mapping object |
| 41 |
const blockCSSGenerators = { |
| 42 |
"sp-smart-post-show/section-heading": sectionHeadingDynamicCSS, |
| 43 |
"sp-smart-post-show/post-carousel": postCarouselDynamicCSS, |
| 44 |
"sp-smart-post-show/post-slider": postSliderDynamicCSS, |
| 45 |
"sp-smart-post-show/post-slider-two": postSliderTwoDynamicCSS, |
| 46 |
"sp-smart-post-show/thumbnail-slider": postThumbnailDynamicCSS, |
| 47 |
"sp-smart-post-show/thumbnail-slider-two": postThumbnailTwoDynamicCSS, |
| 48 |
"sp-smart-post-show/post-grid-one": gridOneDynamicCSS, |
| 49 |
"sp-smart-post-show/post-grid-two": gridTwoDynamicCSS, |
| 50 |
"sp-smart-post-show/post-grid-three": gridThreeDynamicCSS, |
| 51 |
"sp-smart-post-show/post-grid-four": gridFourDynamicCSS, |
| 52 |
"sp-smart-post-show/post-grid-five": gridFiveDynamicCSS, |
| 53 |
"sp-smart-post-show/post-grid-six": gridSixDynamicCSS, |
| 54 |
"sp-smart-post-show/post-list-one": listOneDynamicCSS, |
| 55 |
"sp-smart-post-show/post-list-two": listTwoDynamicCSS, |
| 56 |
"sp-smart-post-show/post-list-three": listThreeDynamicCSS, |
| 57 |
"sp-smart-post-show/post-timeline-one": timelineOneDynamicCSS, |
| 58 |
"sp-smart-post-show/post-timeline-two": timelineTwoDynamicCSS, |
| 59 |
"sp-smart-post-show/post-timeline-three": timelineThreeDynamicCSS, |
| 60 |
"sp-smart-post-show/container": containerDynamicCSS, |
| 61 |
"sp-smart-post-show/column": columnDynamicCSS, |
| 62 |
"sp-smart-post-show/social-profiles": socialProfilesDynamicCSS, |
| 63 |
"sp-smart-post-show/social-profile-item": socialItemDynamicCSS, |
| 64 |
"sp-smart-post-show/pagination": paginationDynamicCSS, |
| 65 |
"sp-smart-post-show/buttons": buttonsDynamicCSS, |
| 66 |
"sp-smart-post-show/button": buttonDynamicCSS, |
| 67 |
"sp-smart-post-show/news-ticker": NewsDynamicCssFn, |
| 68 |
"sp-smart-post-show/taxonomy-filter": taxonomyFilterDynamicCSS, |
| 69 |
"sp-smart-post-show/author-filter": authorFilterDynamicCSS, |
| 70 |
"sp-smart-post-show/live-filter": liveFilterDynamicCSS, |
| 71 |
// 'sp-smart-post-show/smart-post-parent': smartPostParentDynamicCSS, |
| 72 |
"sp-smart-post-show/taxonomy": taxonomyDynamicCSS, |
| 73 |
"sp-smart-post-show/smart-image": smartImageDynamicCSS, |
| 74 |
"sp-smart-post-show/smart-search": smartSearchDynamicCss, |
| 75 |
"sp-smart-post-show/table-of-content": TocDynamicCss, |
| 76 |
"sp-smart-post-show/post-carousel-two": CarouselTwoDynamicCss, |
| 77 |
"sp-smart-post-show/smart-info-box": smartInfoBoxDynamicCss, |
| 78 |
"sp-smart-post-show/smart-lists": ListsDynamicCssFn, |
| 79 |
"sp-smart-post-show/smart-list": ListDynamicCssFn, |
| 80 |
}; |
| 81 |
|
| 82 |
/** |
| 83 |
* Central function to generate CSS for any block |
| 84 |
* @param {string} blockName - The block name |
| 85 |
* @param {Object} attributes - Block attributes |
| 86 |
* @param {string} page - Context (editor/frontend) |
| 87 |
* @returns {string} Generated CSS |
| 88 |
*/ |
| 89 |
const generateBlockCSS = (attributes, blockName, page = "frontend") => { |
| 90 |
const { uniqueId } = attributes; |
| 91 |
|
| 92 |
if (!uniqueId) { |
| 93 |
return ""; |
| 94 |
} |
| 95 |
// Get the CSS generator function from the mapping object |
| 96 |
const cssGenerator = blockCSSGenerators[blockName]; |
| 97 |
|
| 98 |
// If a generator exists for this block, call it |
| 99 |
if (cssGenerator && typeof cssGenerator === "function") { |
| 100 |
return cssGenerator(attributes, page); |
| 101 |
} |
| 102 |
|
| 103 |
// Return undefined for unknown blocks (no default CSS) |
| 104 |
return; |
| 105 |
}; |
| 106 |
|
| 107 |
// Optional: Create a default export for convenience |
| 108 |
export default generateBlockCSS; |
| 109 |
|