@marvalt/wparser 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +844 -804
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +46 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +844 -805
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts +2 -2
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/registry/enhancedRegistry.d.ts +2 -2
- package/dist/registry/enhancedRegistry.d.ts.map +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +19 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1390,7 +1390,7 @@ function renderBlock(block, registry, key, options, page) {
|
|
|
1390
1390
|
const children = block.innerBlocks && block.innerBlocks.length
|
|
1391
1391
|
? block.innerBlocks.map((child, i) => renderBlock(child, registry, `${key}-${i}`, options, page))
|
|
1392
1392
|
: undefined;
|
|
1393
|
-
const node = Renderer({ block, children, context: { registry, page } });
|
|
1393
|
+
const node = Renderer({ block, children, context: { registry, page, colorMapper: registry.colorMapper } });
|
|
1394
1394
|
if (options?.debugWrappers) {
|
|
1395
1395
|
return (jsxRuntimeExports.jsx("div", { "data-block": block.name, className: "wp-block", children: node }, key));
|
|
1396
1396
|
}
|
|
@@ -1662,98 +1662,6 @@ function extractImageUrlWithFallback(block) {
|
|
|
1662
1662
|
return getImageUrl(block);
|
|
1663
1663
|
}
|
|
1664
1664
|
|
|
1665
|
-
/**
|
|
1666
|
-
* Style mapping utilities
|
|
1667
|
-
* Maps WordPress block attributes to Tailwind CSS classes
|
|
1668
|
-
*/
|
|
1669
|
-
/**
|
|
1670
|
-
* Map WordPress alignment to Tailwind classes
|
|
1671
|
-
*/
|
|
1672
|
-
function getAlignmentClasses(align) {
|
|
1673
|
-
if (!align)
|
|
1674
|
-
return '';
|
|
1675
|
-
switch (align) {
|
|
1676
|
-
case 'full':
|
|
1677
|
-
return 'w-full';
|
|
1678
|
-
case 'wide':
|
|
1679
|
-
return 'max-w-7xl mx-auto';
|
|
1680
|
-
case 'center':
|
|
1681
|
-
return 'mx-auto';
|
|
1682
|
-
case 'left':
|
|
1683
|
-
return 'mr-auto';
|
|
1684
|
-
case 'right':
|
|
1685
|
-
return 'ml-auto';
|
|
1686
|
-
default:
|
|
1687
|
-
return '';
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
/**
|
|
1691
|
-
* Map WordPress text alignment to Tailwind classes
|
|
1692
|
-
*/
|
|
1693
|
-
function getTextAlignClasses(textAlign) {
|
|
1694
|
-
if (!textAlign)
|
|
1695
|
-
return '';
|
|
1696
|
-
switch (textAlign) {
|
|
1697
|
-
case 'center':
|
|
1698
|
-
return 'text-center';
|
|
1699
|
-
case 'left':
|
|
1700
|
-
return 'text-left';
|
|
1701
|
-
case 'right':
|
|
1702
|
-
return 'text-right';
|
|
1703
|
-
default:
|
|
1704
|
-
return '';
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
/**
|
|
1708
|
-
* Map WordPress font size to Tailwind classes
|
|
1709
|
-
*/
|
|
1710
|
-
function getFontSizeClasses(fontSize) {
|
|
1711
|
-
if (!fontSize)
|
|
1712
|
-
return '';
|
|
1713
|
-
// Map WordPress font sizes to Tailwind
|
|
1714
|
-
const sizeMap = {
|
|
1715
|
-
'small': 'text-sm',
|
|
1716
|
-
'medium': 'text-base',
|
|
1717
|
-
'large': 'text-lg',
|
|
1718
|
-
'x-large': 'text-xl',
|
|
1719
|
-
'xx-large': 'text-3xl',
|
|
1720
|
-
'xxx-large': 'text-4xl',
|
|
1721
|
-
};
|
|
1722
|
-
return sizeMap[fontSize] || '';
|
|
1723
|
-
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Get container classes based on layout and alignment
|
|
1726
|
-
*/
|
|
1727
|
-
function getContainerClasses(align, layout) {
|
|
1728
|
-
const alignClass = getAlignmentClasses(align);
|
|
1729
|
-
// If layout is constrained, use container
|
|
1730
|
-
if (layout?.type === 'constrained') {
|
|
1731
|
-
return align === 'full' ? 'w-full' : 'container';
|
|
1732
|
-
}
|
|
1733
|
-
return alignClass || 'container';
|
|
1734
|
-
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Get spacing classes for sections
|
|
1737
|
-
*/
|
|
1738
|
-
function getSectionSpacingClasses() {
|
|
1739
|
-
return 'py-16 md:py-24';
|
|
1740
|
-
}
|
|
1741
|
-
/**
|
|
1742
|
-
* Get content spacing classes
|
|
1743
|
-
*/
|
|
1744
|
-
function getContentSpacingClasses() {
|
|
1745
|
-
return 'space-y-6';
|
|
1746
|
-
}
|
|
1747
|
-
/**
|
|
1748
|
-
* Build className string from multiple class sources
|
|
1749
|
-
*/
|
|
1750
|
-
function buildClassName(...classes) {
|
|
1751
|
-
return classes
|
|
1752
|
-
.filter((cls) => Boolean(cls && cls.trim()))
|
|
1753
|
-
.join(' ')
|
|
1754
|
-
.trim();
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
1665
|
/**
|
|
1758
1666
|
* Cloudflare Images URL helpers for wparser package
|
|
1759
1667
|
* Formats Cloudflare image URLs with variants for optimal performance
|
|
@@ -1790,834 +1698,965 @@ const getCloudflareVariantUrl = (url, options) => {
|
|
|
1790
1698
|
return `${base}/${variant}`;
|
|
1791
1699
|
};
|
|
1792
1700
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1701
|
+
/**
|
|
1702
|
+
* Extract background image URL from a block
|
|
1703
|
+
* Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
|
|
1704
|
+
*/
|
|
1705
|
+
function extractBackgroundImage(block, page) {
|
|
1795
1706
|
const attrs = block.attributes || {};
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
if (hasShortcodes && context.registry.shortcodes) {
|
|
1800
|
-
const parts = renderTextWithShortcodes(content, context.registry);
|
|
1801
|
-
// Check if any part is a block-level element (section, div, etc.)
|
|
1802
|
-
// If so, render without wrapping in <p> to avoid DOM nesting violations
|
|
1803
|
-
const isBlockLevelElement = (element) => {
|
|
1804
|
-
if (!React.isValidElement(element)) {
|
|
1805
|
-
return false;
|
|
1806
|
-
}
|
|
1807
|
-
const type = element.type;
|
|
1808
|
-
// Check for block-level HTML elements
|
|
1809
|
-
if (typeof type === 'string' && ['section', 'div', 'article', 'header', 'footer', 'aside', 'nav'].includes(type)) {
|
|
1810
|
-
return true;
|
|
1811
|
-
}
|
|
1812
|
-
// Check if it's React.Fragment - recursively check its children
|
|
1813
|
-
if (type === React.Fragment) {
|
|
1814
|
-
const fragmentProps = element.props;
|
|
1815
|
-
const children = React.Children.toArray(fragmentProps.children);
|
|
1816
|
-
return children.some((child) => isBlockLevelElement(child));
|
|
1817
|
-
}
|
|
1818
|
-
// Check if it's a React component (likely block-level)
|
|
1819
|
-
// Most custom components render block-level content
|
|
1820
|
-
if (typeof type === 'function' || (typeof type === 'object' && type !== null && type !== React.Fragment)) {
|
|
1821
|
-
return true;
|
|
1822
|
-
}
|
|
1823
|
-
return false;
|
|
1824
|
-
};
|
|
1825
|
-
const hasBlockLevelContent = React.Children.toArray(parts).some((part) => isBlockLevelElement(part));
|
|
1826
|
-
if (hasBlockLevelContent) {
|
|
1827
|
-
// Render block-level content without <p> wrapper
|
|
1828
|
-
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: parts });
|
|
1829
|
-
}
|
|
1830
|
-
return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: parts });
|
|
1707
|
+
// Check if block uses featured image
|
|
1708
|
+
if (attrs['useFeaturedImage'] === true && page?._embedded?.['wp:featuredmedia']?.[0]?.source_url) {
|
|
1709
|
+
return page._embedded['wp:featuredmedia'][0].source_url;
|
|
1831
1710
|
}
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1711
|
+
// Use the improved extraction function that handles incomplete cloudflareUrl
|
|
1712
|
+
// This will check cloudflareUrl first, then innerHTML, then regular attributes
|
|
1713
|
+
return extractImageUrlWithFallback(block);
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Extract image URL from a block
|
|
1717
|
+
* Returns Cloudflare URL if available, otherwise WordPress URL
|
|
1718
|
+
*/
|
|
1719
|
+
function extractImageUrl(block) {
|
|
1720
|
+
// Use the improved extraction function that handles incomplete cloudflareUrl
|
|
1721
|
+
return extractImageUrlWithFallback(block);
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Extract image attributes (url, alt, width, height)
|
|
1725
|
+
*/
|
|
1726
|
+
function extractImageAttributes(block) {
|
|
1727
|
+
return getImageAttributes(block);
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Extract title/heading text from a block
|
|
1731
|
+
*/
|
|
1732
|
+
function extractTitle(block) {
|
|
1835
1733
|
const attrs = block.attributes || {};
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
if (isCloudflareImageUrl(imageUrl)) {
|
|
1852
|
-
const width = imageAttrs.width || 1024;
|
|
1853
|
-
const height = imageAttrs.height;
|
|
1854
|
-
imageUrl = getCloudflareVariantUrl(imageUrl, { width, height });
|
|
1855
|
-
}
|
|
1856
|
-
return (jsxRuntimeExports.jsx("img", { src: imageUrl, alt: imageAttrs.alt, width: imageAttrs.width, height: imageAttrs.height, className: "w-full h-auto rounded-lg object-cover", style: { maxWidth: '100%', height: 'auto' }, loading: "lazy" }));
|
|
1857
|
-
};
|
|
1858
|
-
const List = ({ block, children }) => {
|
|
1734
|
+
const title = attrs['title'] || attrs['content'] || getBlockTextContent(block);
|
|
1735
|
+
return typeof title === 'string' ? title.trim() : null;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Extract content/text from a block
|
|
1739
|
+
* Returns React node for rendering
|
|
1740
|
+
*/
|
|
1741
|
+
function extractContent(block, context) {
|
|
1742
|
+
const text = getBlockTextContent(block);
|
|
1743
|
+
return text || null;
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Extract media position from media-text block
|
|
1747
|
+
*/
|
|
1748
|
+
function extractMediaPosition(block) {
|
|
1859
1749
|
const attrs = block.attributes || {};
|
|
1860
|
-
const
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
const Group = ({ block, children }) => {
|
|
1750
|
+
const position = attrs['mediaPosition'] || 'left';
|
|
1751
|
+
return position === 'right' ? 'right' : 'left';
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Extract vertical alignment from block
|
|
1755
|
+
*/
|
|
1756
|
+
function extractVerticalAlignment(block) {
|
|
1868
1757
|
const attrs = block.attributes || {};
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
: containerClass;
|
|
1880
|
-
return (jsxRuntimeExports.jsx("div", { className: buildClassName(finalContainerClass, spacingClass), children: children }));
|
|
1881
|
-
};
|
|
1882
|
-
const Columns = ({ block, children }) => {
|
|
1758
|
+
const alignment = attrs['verticalAlignment'] || 'center';
|
|
1759
|
+
if (alignment === 'top' || alignment === 'bottom') {
|
|
1760
|
+
return alignment;
|
|
1761
|
+
}
|
|
1762
|
+
return 'center';
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Extract alignment (full, wide, contained) from block
|
|
1766
|
+
*/
|
|
1767
|
+
function extractAlignment(block) {
|
|
1883
1768
|
const attrs = block.attributes || {};
|
|
1884
1769
|
const align = attrs['align'];
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1770
|
+
if (align === 'full' || align === 'wide') {
|
|
1771
|
+
return align;
|
|
1772
|
+
}
|
|
1773
|
+
return 'contained';
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Extract overlay color from cover block
|
|
1777
|
+
*/
|
|
1778
|
+
function extractOverlayColor(block) {
|
|
1889
1779
|
const attrs = block.attributes || {};
|
|
1890
|
-
const
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1780
|
+
const overlayColor = attrs['overlayColor'];
|
|
1781
|
+
if (typeof overlayColor === 'string') {
|
|
1782
|
+
return overlayColor;
|
|
1783
|
+
}
|
|
1784
|
+
return null;
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* Extract dim ratio (overlay opacity) from cover block
|
|
1788
|
+
*/
|
|
1789
|
+
function extractDimRatio(block) {
|
|
1897
1790
|
const attrs = block.attributes || {};
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
// Extract from innerHTML if not in attributes (buttons often store data in innerHTML)
|
|
1902
|
-
if (!url && block.innerHTML) {
|
|
1903
|
-
const linkMatch = block.innerHTML.match(/<a[^>]+href=["']([^"']+)["'][^>]*>([^<]+)<\/a>/i);
|
|
1904
|
-
if (linkMatch) {
|
|
1905
|
-
url = linkMatch[1];
|
|
1906
|
-
text = linkMatch[2] || text;
|
|
1907
|
-
}
|
|
1791
|
+
const dimRatio = attrs['dimRatio'];
|
|
1792
|
+
if (typeof dimRatio === 'number') {
|
|
1793
|
+
return dimRatio;
|
|
1908
1794
|
}
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1795
|
+
return 0;
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Extract min height from block
|
|
1799
|
+
*/
|
|
1800
|
+
function extractMinHeight(block) {
|
|
1801
|
+
const attrs = block.attributes || {};
|
|
1802
|
+
const minHeight = attrs['minHeight'];
|
|
1803
|
+
const minHeightUnit = attrs['minHeightUnit'] || 'vh';
|
|
1804
|
+
if (typeof minHeight === 'number') {
|
|
1805
|
+
return { value: minHeight, unit: minHeightUnit };
|
|
1912
1806
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
return (jsxRuntimeExports.jsx("a", { href: url || '#', className: "inline-flex items-center justify-center rounded-md bg-primary px-6 py-3 text-primary-foreground font-medium hover:bg-primary/90 transition-colors", ...linkProps, children: buttonText }));
|
|
1920
|
-
};
|
|
1921
|
-
const Cover = ({ block, children }) => {
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Extract heading level from heading block
|
|
1811
|
+
*/
|
|
1812
|
+
function extractHeadingLevel(block) {
|
|
1922
1813
|
const attrs = block.attributes || {};
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
let bgImageUrl = null;
|
|
1927
|
-
// First, try cloudflareUrl if it's valid
|
|
1928
|
-
if (cloudflareUrl && isValidCloudflareUrl(cloudflareUrl)) {
|
|
1929
|
-
bgImageUrl = cloudflareUrl;
|
|
1814
|
+
const level = attrs['level'];
|
|
1815
|
+
if (typeof level === 'number' && level >= 1 && level <= 6) {
|
|
1816
|
+
return level;
|
|
1930
1817
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1818
|
+
return 2; // Default to h2
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Extract text alignment from block
|
|
1822
|
+
*/
|
|
1823
|
+
function extractTextAlign(block) {
|
|
1824
|
+
const attrs = block.attributes || {};
|
|
1825
|
+
const align = attrs['align'] || attrs['textAlign'];
|
|
1826
|
+
if (align === 'left' || align === 'center' || align === 'right') {
|
|
1827
|
+
return align;
|
|
1934
1828
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1829
|
+
return null;
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Extract font size from block
|
|
1833
|
+
*/
|
|
1834
|
+
function extractFontSize(block) {
|
|
1835
|
+
const attrs = block.attributes || {};
|
|
1836
|
+
const fontSize = attrs['fontSize'];
|
|
1837
|
+
return typeof fontSize === 'string' ? fontSize : null;
|
|
1838
|
+
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Convert image URL to Cloudflare variant if it's a Cloudflare URL
|
|
1841
|
+
*/
|
|
1842
|
+
function convertImageToCloudflareVariant(url, options = {}) {
|
|
1843
|
+
if (!url)
|
|
1844
|
+
return null;
|
|
1845
|
+
if (isCloudflareImageUrl(url)) {
|
|
1846
|
+
const width = options.width || 1024;
|
|
1847
|
+
const height = options.height;
|
|
1848
|
+
return getCloudflareVariantUrl(url, { width, height });
|
|
1938
1849
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1850
|
+
return url;
|
|
1851
|
+
}
|
|
1852
|
+
/**
|
|
1853
|
+
* Extract title from innerBlocks (finds first heading block)
|
|
1854
|
+
*/
|
|
1855
|
+
function extractTitleFromInnerBlocks(block) {
|
|
1856
|
+
const innerBlocks = block.innerBlocks || [];
|
|
1857
|
+
// Recursively search for heading blocks
|
|
1858
|
+
for (const innerBlock of innerBlocks) {
|
|
1859
|
+
if (innerBlock.name === 'core/heading') {
|
|
1860
|
+
return getBlockTextContent(innerBlock);
|
|
1944
1861
|
}
|
|
1862
|
+
// Recursively search nested blocks
|
|
1863
|
+
const nestedTitle = extractTitleFromInnerBlocks(innerBlock);
|
|
1864
|
+
if (nestedTitle)
|
|
1865
|
+
return nestedTitle;
|
|
1945
1866
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1867
|
+
return null;
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Extract subtitle/description from innerBlocks (finds first paragraph block)
|
|
1871
|
+
*/
|
|
1872
|
+
function extractSubtitleFromInnerBlocks(block) {
|
|
1873
|
+
const innerBlocks = block.innerBlocks || [];
|
|
1874
|
+
// Recursively search for paragraph blocks
|
|
1875
|
+
for (const innerBlock of innerBlocks) {
|
|
1876
|
+
if (innerBlock.name === 'core/paragraph') {
|
|
1877
|
+
const text = getBlockTextContent(innerBlock);
|
|
1878
|
+
if (text && text.trim()) {
|
|
1879
|
+
return text;
|
|
1880
|
+
}
|
|
1960
1881
|
}
|
|
1882
|
+
// Recursively search nested blocks
|
|
1883
|
+
const nestedSubtitle = extractSubtitleFromInnerBlocks(innerBlock);
|
|
1884
|
+
if (nestedSubtitle)
|
|
1885
|
+
return nestedSubtitle;
|
|
1961
1886
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
const MediaText = ({ block, children, context }) => {
|
|
1970
|
-
const attrs = block.attributes || {};
|
|
1971
|
-
const { mediaPosition = 'left', verticalAlignment = 'center', imageFill = false, align, } = attrs;
|
|
1972
|
-
// Access innerBlocks to identify media vs content
|
|
1887
|
+
return null;
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Extract buttons from innerBlocks (finds buttons block and extracts button data)
|
|
1891
|
+
*/
|
|
1892
|
+
function extractButtonsFromInnerBlocks(block) {
|
|
1893
|
+
const buttons = [];
|
|
1973
1894
|
const innerBlocks = block.innerBlocks || [];
|
|
1974
|
-
// Find
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
// Convert to Cloudflare variant if it's a Cloudflare URL
|
|
1986
|
-
// extractImageUrlWithFallback already handles incomplete cloudflareUrl by falling back to innerHTML
|
|
1987
|
-
const finalImageUrl = isCloudflareImageUrl(imageUrl)
|
|
1988
|
-
? getCloudflareVariantUrl(imageUrl, { width: 1024 })
|
|
1989
|
-
: imageUrl;
|
|
1990
|
-
mediaElement = (jsxRuntimeExports.jsx("img", { src: finalImageUrl, alt: "", className: "w-full h-auto rounded-lg shadow-lg object-cover", style: { maxWidth: '100%', height: 'auto' }, loading: "lazy" }));
|
|
1895
|
+
// Find buttons block
|
|
1896
|
+
const findButtonsBlock = (blocks) => {
|
|
1897
|
+
for (const innerBlock of blocks) {
|
|
1898
|
+
if (innerBlock.name === 'core/buttons') {
|
|
1899
|
+
return innerBlock;
|
|
1900
|
+
}
|
|
1901
|
+
if (innerBlock.innerBlocks) {
|
|
1902
|
+
const found = findButtonsBlock(innerBlock.innerBlocks);
|
|
1903
|
+
if (found)
|
|
1904
|
+
return found;
|
|
1905
|
+
}
|
|
1991
1906
|
}
|
|
1907
|
+
return null;
|
|
1908
|
+
};
|
|
1909
|
+
const buttonsBlock = findButtonsBlock(innerBlocks);
|
|
1910
|
+
if (!buttonsBlock || !buttonsBlock.innerBlocks) {
|
|
1911
|
+
return buttons;
|
|
1992
1912
|
}
|
|
1993
|
-
//
|
|
1994
|
-
const
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
1913
|
+
// Extract button data from button blocks
|
|
1914
|
+
for (const buttonBlock of buttonsBlock.innerBlocks) {
|
|
1915
|
+
if (buttonBlock.name === 'core/button') {
|
|
1916
|
+
const attrs = buttonBlock.attributes || {};
|
|
1917
|
+
const url = attrs['url'];
|
|
1918
|
+
const text = attrs['text'] || getBlockTextContent(buttonBlock);
|
|
1919
|
+
// Try to extract from innerHTML if not in attributes
|
|
1920
|
+
if (!url && buttonBlock.innerHTML) {
|
|
1921
|
+
const linkMatch = buttonBlock.innerHTML.match(/<a[^>]+href=["']([^"']+)["'][^>]*>([^<]+)<\/a>/i);
|
|
1922
|
+
if (linkMatch) {
|
|
1923
|
+
const extractedUrl = linkMatch[1];
|
|
1924
|
+
const extractedText = linkMatch[2] || text;
|
|
1925
|
+
if (extractedUrl) {
|
|
1926
|
+
buttons.push({
|
|
1927
|
+
text: extractedText || 'Learn More',
|
|
1928
|
+
url: extractedUrl,
|
|
1929
|
+
isExternal: extractedUrl.startsWith('http://') || extractedUrl.startsWith('https://'),
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
else if (url && text) {
|
|
1935
|
+
buttons.push({
|
|
1936
|
+
text,
|
|
1937
|
+
url,
|
|
1938
|
+
isExternal: url.startsWith('http://') || url.startsWith('https://'),
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
2017
1942
|
}
|
|
2018
|
-
|
|
2019
|
-
const verticalAlignClass = verticalAlignment === 'top' ? 'items-start' :
|
|
2020
|
-
verticalAlignment === 'bottom' ? 'items-end' :
|
|
2021
|
-
'items-center';
|
|
2022
|
-
// Stack on mobile
|
|
2023
|
-
const stackClass = 'flex-col md:flex-row';
|
|
2024
|
-
// Media position determines order
|
|
2025
|
-
const isMediaRight = mediaPosition === 'right';
|
|
2026
|
-
return (jsxRuntimeExports.jsx("div", { className: buildClassName(alignClass, spacingClass), children: jsxRuntimeExports.jsxs("div", { className: buildClassName('flex', stackClass, verticalAlignClass, 'gap-6 lg:gap-12', 'w-full'), children: [jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-2' : 'order-1', imageFill ? 'w-full md:w-1/2' : 'w-full md:w-1/2', 'min-w-0', // Allow flex item to shrink below content size
|
|
2027
|
-
'overflow-hidden' // Ensure images don't overflow
|
|
2028
|
-
), children: mediaElement || jsxRuntimeExports.jsx("div", { className: "bg-gray-200 h-64 rounded-lg" }) }), jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-1' : 'order-2', 'w-full md:w-1/2', // Explicit width to ensure proper sizing
|
|
2029
|
-
'min-w-0', // Allow flex item to shrink below content size
|
|
2030
|
-
getContentSpacingClasses()), children: contentElements.length > 0 ? contentElements : children })] }) }));
|
|
2031
|
-
};
|
|
2032
|
-
const Fallback = ({ block, children }) => {
|
|
2033
|
-
// Minimal fallback; do not render innerHTML directly in v1 for safety
|
|
2034
|
-
return jsxRuntimeExports.jsx("div", { "data-unknown-block": block.name, children: children });
|
|
2035
|
-
};
|
|
2036
|
-
function createDefaultRegistry() {
|
|
2037
|
-
const renderers = {
|
|
2038
|
-
'core/paragraph': Paragraph,
|
|
2039
|
-
'core/heading': Heading,
|
|
2040
|
-
'core/image': Image,
|
|
2041
|
-
'core/list': List,
|
|
2042
|
-
'core/list-item': ListItem,
|
|
2043
|
-
'core/group': Group,
|
|
2044
|
-
'core/columns': Columns,
|
|
2045
|
-
'core/column': Column,
|
|
2046
|
-
'core/separator': Separator,
|
|
2047
|
-
'core/button': ButtonBlock,
|
|
2048
|
-
'core/buttons': ({ block, children }) => {
|
|
2049
|
-
const attrs = block.attributes || {};
|
|
2050
|
-
const layout = attrs['layout'];
|
|
2051
|
-
const justifyContent = layout?.justifyContent || 'left';
|
|
2052
|
-
const justifyClass = justifyContent === 'center' ? 'justify-center' :
|
|
2053
|
-
justifyContent === 'right' ? 'justify-end' :
|
|
2054
|
-
'justify-start';
|
|
2055
|
-
return jsxRuntimeExports.jsx("div", { className: buildClassName('flex flex-wrap gap-3', justifyClass), children: children });
|
|
2056
|
-
},
|
|
2057
|
-
'core/quote': ({ children }) => jsxRuntimeExports.jsx("blockquote", { className: "border-l-4 pl-4 italic", children: children }),
|
|
2058
|
-
'core/code': ({ block }) => (jsxRuntimeExports.jsx("pre", { className: "bg-gray-100 p-3 rounded text-sm overflow-auto", children: jsxRuntimeExports.jsx("code", { children: getString(block) }) })),
|
|
2059
|
-
'core/preformatted': ({ block }) => jsxRuntimeExports.jsx("pre", { children: getString(block) }),
|
|
2060
|
-
'core/table': ({ children }) => jsxRuntimeExports.jsx("div", { className: "overflow-x-auto", children: jsxRuntimeExports.jsx("table", { className: "table-auto w-full", children: children }) }),
|
|
2061
|
-
'core/table-row': ({ children }) => jsxRuntimeExports.jsx("tr", { children: children }),
|
|
2062
|
-
'core/table-cell': ({ children }) => jsxRuntimeExports.jsx("td", { className: "border px-3 py-2", children: children }),
|
|
2063
|
-
// Cover block - hero sections with background images
|
|
2064
|
-
'core/cover': Cover,
|
|
2065
|
-
// Media & Text block - side-by-side media and content
|
|
2066
|
-
'core/media-text': MediaText,
|
|
2067
|
-
// HTML block - render innerHTML as-is
|
|
2068
|
-
// Note: Shortcodes in HTML blocks are not parsed (they would need to be in text content)
|
|
2069
|
-
'core/html': ({ block }) => {
|
|
2070
|
-
const html = block.innerHTML || '';
|
|
2071
|
-
return jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: html } });
|
|
2072
|
-
},
|
|
2073
|
-
};
|
|
2074
|
-
return {
|
|
2075
|
-
renderers,
|
|
2076
|
-
shortcodes: {}, // Empty by default - apps extend this
|
|
2077
|
-
fallback: Fallback,
|
|
2078
|
-
};
|
|
2079
|
-
}
|
|
2080
|
-
// Legacy function for backward compatibility - use getBlockTextContent instead
|
|
2081
|
-
function getString(block) {
|
|
2082
|
-
return getBlockTextContent(block);
|
|
1943
|
+
return buttons;
|
|
2083
1944
|
}
|
|
2084
|
-
|
|
2085
1945
|
/**
|
|
2086
|
-
*
|
|
1946
|
+
* Extract text alignment from inner blocks
|
|
1947
|
+
* Recursively searches for heading or paragraph blocks with textAlign attribute
|
|
1948
|
+
* Also checks group blocks for justifyContent in layout
|
|
1949
|
+
* Priority: heading/paragraph textAlign takes precedence over group justifyContent
|
|
2087
1950
|
*/
|
|
2088
|
-
function
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
return false;
|
|
1951
|
+
function extractTextAlignFromInnerBlocks(block) {
|
|
1952
|
+
const innerBlocks = block.innerBlocks || [];
|
|
1953
|
+
// First, recursively search for heading or paragraph blocks with textAlign
|
|
1954
|
+
// (These take priority over group justifyContent)
|
|
1955
|
+
for (const innerBlock of innerBlocks) {
|
|
1956
|
+
if (innerBlock.name === 'core/heading' || innerBlock.name === 'core/paragraph') {
|
|
1957
|
+
const attrs = innerBlock.attributes || {};
|
|
1958
|
+
const textAlign = attrs['textAlign'];
|
|
1959
|
+
if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
|
|
1960
|
+
return textAlign;
|
|
2099
1961
|
}
|
|
2100
1962
|
}
|
|
1963
|
+
// Recursively search nested blocks for headings/paragraphs first
|
|
1964
|
+
const nestedAlign = extractTextAlignFromInnerBlocks(innerBlock);
|
|
1965
|
+
if (nestedAlign)
|
|
1966
|
+
return nestedAlign;
|
|
2101
1967
|
}
|
|
2102
|
-
//
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
1968
|
+
// Only check group blocks if no heading/paragraph alignment found
|
|
1969
|
+
for (const innerBlock of innerBlocks) {
|
|
1970
|
+
if (innerBlock.name === 'core/group') {
|
|
1971
|
+
const attrs = innerBlock.attributes || {};
|
|
1972
|
+
const layout = attrs['layout'];
|
|
1973
|
+
const justifyContent = layout?.justifyContent;
|
|
1974
|
+
if (justifyContent === 'left')
|
|
1975
|
+
return 'left';
|
|
1976
|
+
if (justifyContent === 'center')
|
|
1977
|
+
return 'center';
|
|
1978
|
+
if (justifyContent === 'right')
|
|
1979
|
+
return 'right';
|
|
2112
1980
|
}
|
|
2113
1981
|
}
|
|
2114
|
-
return
|
|
1982
|
+
return null;
|
|
2115
1983
|
}
|
|
2116
1984
|
/**
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
1985
|
+
* Parse contentPosition string into horizontal and vertical alignment
|
|
1986
|
+
* Format: "horizontal vertical" (e.g., "center center", "left top", "right bottom")
|
|
2119
1987
|
*/
|
|
2120
|
-
function
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
1988
|
+
function parseContentPosition(contentPosition) {
|
|
1989
|
+
if (!contentPosition) {
|
|
1990
|
+
return { horizontal: 'left', vertical: 'center' };
|
|
1991
|
+
}
|
|
1992
|
+
const parts = contentPosition.trim().split(/\s+/);
|
|
1993
|
+
const horizontal = parts[0] || 'left';
|
|
1994
|
+
const vertical = parts[1] || 'center';
|
|
1995
|
+
return {
|
|
1996
|
+
horizontal: (horizontal === 'center' || horizontal === 'right' ? horizontal : 'left'),
|
|
1997
|
+
vertical: (vertical === 'top' || vertical === 'bottom' ? vertical : 'center'),
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Extract video iframe HTML from innerBlocks (finds HTML block with iframe)
|
|
2002
|
+
*/
|
|
2003
|
+
function extractVideoIframeFromInnerBlocks(block) {
|
|
2004
|
+
const innerBlocks = block.innerBlocks || [];
|
|
2005
|
+
// Recursively search for HTML blocks with iframe
|
|
2006
|
+
for (const innerBlock of innerBlocks) {
|
|
2007
|
+
if (innerBlock.name === 'core/html' && innerBlock.innerHTML) {
|
|
2008
|
+
// Check if innerHTML contains an iframe
|
|
2009
|
+
if (innerBlock.innerHTML.includes('<iframe')) {
|
|
2010
|
+
return innerBlock.innerHTML;
|
|
2011
|
+
}
|
|
2127
2012
|
}
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
return mapping;
|
|
2013
|
+
// Recursively search nested blocks
|
|
2014
|
+
if (innerBlock.innerBlocks) {
|
|
2015
|
+
const nestedVideo = extractVideoIframeFromInnerBlocks(innerBlock);
|
|
2016
|
+
if (nestedVideo)
|
|
2017
|
+
return nestedVideo;
|
|
2134
2018
|
}
|
|
2135
2019
|
}
|
|
2136
2020
|
return null;
|
|
2137
2021
|
}
|
|
2138
|
-
|
|
2139
2022
|
/**
|
|
2140
|
-
*
|
|
2023
|
+
* Extract and map background color from block attributes
|
|
2024
|
+
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
2141
2025
|
*
|
|
2142
|
-
*
|
|
2143
|
-
*
|
|
2144
|
-
* to the default renderer.
|
|
2026
|
+
* WordPress controls which color is applied (via backgroundColor attribute),
|
|
2027
|
+
* app controls what it means (via colorMapper function)
|
|
2145
2028
|
*
|
|
2146
|
-
* @param
|
|
2147
|
-
* @param
|
|
2148
|
-
* @returns
|
|
2029
|
+
* @param block - WordPress block to extract background color from
|
|
2030
|
+
* @param context - Render context containing optional colorMapper
|
|
2031
|
+
* @returns CSS class string (e.g., 'bg-gray-100') or null if no mapping
|
|
2149
2032
|
*
|
|
2150
2033
|
* @example
|
|
2151
2034
|
* ```ts
|
|
2152
|
-
*
|
|
2153
|
-
*
|
|
2154
|
-
*
|
|
2155
|
-
* component: HomeHeroSection,
|
|
2156
|
-
* extractProps: (block) => ({
|
|
2157
|
-
* backgroundImage: extractBackgroundImage(block),
|
|
2158
|
-
* title: extractTitle(block),
|
|
2159
|
-
* }),
|
|
2160
|
-
* wrapper: SectionWrapper,
|
|
2161
|
-
* },
|
|
2162
|
-
* ];
|
|
2163
|
-
*
|
|
2164
|
-
* const registry = createEnhancedRegistry(mappings);
|
|
2035
|
+
* // In WordPress, group block has: backgroundColor: "accent-5"
|
|
2036
|
+
* // In app, colorMapper maps: "accent-5" → "bg-gray-100"
|
|
2037
|
+
* // Result: extractBackgroundColor returns "bg-gray-100"
|
|
2165
2038
|
* ```
|
|
2166
2039
|
*/
|
|
2167
|
-
function
|
|
2168
|
-
const
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
...base.renderers,
|
|
2172
|
-
};
|
|
2173
|
-
// Override renderers for blocks that have mappings
|
|
2174
|
-
// We need to check patterns at render time, so we create a wrapper renderer
|
|
2175
|
-
const createPatternRenderer = (blockName) => {
|
|
2176
|
-
return (props) => {
|
|
2177
|
-
const { block, context } = props;
|
|
2178
|
-
// Find matching mapping
|
|
2179
|
-
const mapping = findMatchingMapping(block, mappings);
|
|
2180
|
-
if (mapping) {
|
|
2181
|
-
// Extract props from block
|
|
2182
|
-
const componentProps = mapping.extractProps(block, context);
|
|
2183
|
-
// Render component
|
|
2184
|
-
const Component = mapping.component;
|
|
2185
|
-
const content = jsxRuntimeExports.jsx(Component, { ...componentProps });
|
|
2186
|
-
// Wrap with wrapper if provided
|
|
2187
|
-
if (mapping.wrapper) {
|
|
2188
|
-
const Wrapper = mapping.wrapper;
|
|
2189
|
-
return jsxRuntimeExports.jsx(Wrapper, { block: block, children: content });
|
|
2190
|
-
}
|
|
2191
|
-
return content;
|
|
2192
|
-
}
|
|
2193
|
-
// Fall back to default renderer
|
|
2194
|
-
const defaultRenderer = base.renderers[blockName] || base.fallback;
|
|
2195
|
-
return defaultRenderer(props);
|
|
2196
|
-
};
|
|
2197
|
-
};
|
|
2198
|
-
// For each mapping, override the renderer for that block name
|
|
2199
|
-
for (const mapping of mappings) {
|
|
2200
|
-
const blockName = mapping.pattern.name;
|
|
2201
|
-
if (blockName) {
|
|
2202
|
-
enhancedRenderers[blockName] = createPatternRenderer(blockName);
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
// Create matchBlock function
|
|
2206
|
-
const matchBlock = (block) => {
|
|
2207
|
-
return findMatchingMapping(block, mappings);
|
|
2208
|
-
};
|
|
2209
|
-
return {
|
|
2210
|
-
...base,
|
|
2211
|
-
renderers: enhancedRenderers,
|
|
2212
|
-
mappings,
|
|
2213
|
-
matchBlock,
|
|
2214
|
-
};
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
const WPContent = ({ blocks, registry, className, page }) => {
|
|
2218
|
-
if (!Array.isArray(blocks)) {
|
|
2219
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2220
|
-
// eslint-disable-next-line no-console
|
|
2221
|
-
console.warn('WPContent: invalid blocks prop');
|
|
2222
|
-
}
|
|
2040
|
+
function extractBackgroundColor(block, context) {
|
|
2041
|
+
const attrs = block.attributes || {};
|
|
2042
|
+
const wpColorName = attrs['backgroundColor'] || attrs['background'];
|
|
2043
|
+
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2223
2044
|
return null;
|
|
2224
2045
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2046
|
+
// Use colorMapper from context if available
|
|
2047
|
+
if (context.colorMapper) {
|
|
2048
|
+
return context.colorMapper(wpColorName);
|
|
2227
2049
|
}
|
|
2228
|
-
|
|
2229
|
-
return
|
|
2230
|
-
}
|
|
2050
|
+
// Fallback: return null (no background applied)
|
|
2051
|
+
return null;
|
|
2052
|
+
}
|
|
2231
2053
|
|
|
2232
2054
|
/**
|
|
2233
|
-
*
|
|
2234
|
-
*
|
|
2235
|
-
* - Else, if the page has featured media, render a hero section using the image as background.
|
|
2055
|
+
* Style mapping utilities
|
|
2056
|
+
* Maps WordPress block attributes to Tailwind CSS classes
|
|
2236
2057
|
*/
|
|
2237
|
-
const WPPage = ({ page, registry, className }) => {
|
|
2238
|
-
if (!page || !Array.isArray(page.blocks)) {
|
|
2239
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2240
|
-
// eslint-disable-next-line no-console
|
|
2241
|
-
console.warn('WPPage: invalid page prop');
|
|
2242
|
-
}
|
|
2243
|
-
return null;
|
|
2244
|
-
}
|
|
2245
|
-
if (!registry || !registry.renderers) {
|
|
2246
|
-
throw new Error('WPPage: registry is required');
|
|
2247
|
-
}
|
|
2248
|
-
const hasHeroShortcode = React.useMemo(() => detectHeroShortcode(page.blocks), [page.blocks]);
|
|
2249
|
-
const featured = getFeaturedImage(page);
|
|
2250
|
-
return (jsxRuntimeExports.jsxs("article", { className: className, children: [!hasHeroShortcode && featured && (jsxRuntimeExports.jsx(HeroFromFeatured, { featured: featured, title: page.title?.rendered })), jsxRuntimeExports.jsx(WPContent, { blocks: page.blocks, registry: registry, page: page })] }));
|
|
2251
|
-
};
|
|
2252
|
-
function detectHeroShortcode(blocks) {
|
|
2253
|
-
for (const block of blocks) {
|
|
2254
|
-
const html = (block.innerHTML || '').toLowerCase();
|
|
2255
|
-
if (html.includes('[herosection]'))
|
|
2256
|
-
return true;
|
|
2257
|
-
// Check if this is a cover block (which is a hero section)
|
|
2258
|
-
if (block.name === 'core/cover')
|
|
2259
|
-
return true;
|
|
2260
|
-
if (block.innerBlocks?.length && detectHeroShortcode(block.innerBlocks))
|
|
2261
|
-
return true;
|
|
2262
|
-
}
|
|
2263
|
-
return false;
|
|
2264
|
-
}
|
|
2265
|
-
function getFeaturedImage(page) {
|
|
2266
|
-
const fm = page._embedded?.['wp:featuredmedia'];
|
|
2267
|
-
if (Array.isArray(fm) && fm.length > 0)
|
|
2268
|
-
return fm[0];
|
|
2269
|
-
return null;
|
|
2270
|
-
}
|
|
2271
|
-
const HeroFromFeatured = ({ featured, title }) => {
|
|
2272
|
-
const url = featured.source_url;
|
|
2273
|
-
if (!url)
|
|
2274
|
-
return null;
|
|
2275
|
-
return (jsxRuntimeExports.jsx("section", { className: "w-full h-[40vh] min-h-[280px] flex items-end bg-cover bg-center", style: { backgroundImage: `url(${url})` }, "aria-label": featured.alt_text || title || 'Hero', children: jsxRuntimeExports.jsx("div", { className: "container mx-auto px-4 py-8 bg-gradient-to-t from-black/50 to-transparent w-full", children: title && jsxRuntimeExports.jsx("h1", { className: "text-white text-4xl font-bold drop-shadow", children: title }) }) }));
|
|
2276
|
-
};
|
|
2277
|
-
|
|
2278
|
-
class WPErrorBoundary extends React.Component {
|
|
2279
|
-
constructor(props) {
|
|
2280
|
-
super(props);
|
|
2281
|
-
this.state = { hasError: false };
|
|
2282
|
-
}
|
|
2283
|
-
static getDerivedStateFromError() {
|
|
2284
|
-
return { hasError: true };
|
|
2285
|
-
}
|
|
2286
|
-
componentDidCatch(error) {
|
|
2287
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2288
|
-
// eslint-disable-next-line no-console
|
|
2289
|
-
console.error('WPErrorBoundary caught error:', error);
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
render() {
|
|
2293
|
-
if (this.state.hasError) {
|
|
2294
|
-
return this.props.fallback ?? null;
|
|
2295
|
-
}
|
|
2296
|
-
return this.props.children;
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
2058
|
/**
|
|
2301
|
-
*
|
|
2302
|
-
* Checks various possible sources: cloudflareUrl, url, backgroundImage, innerHTML, featured image
|
|
2059
|
+
* Map WordPress alignment to Tailwind classes
|
|
2303
2060
|
*/
|
|
2304
|
-
function
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2061
|
+
function getAlignmentClasses(align) {
|
|
2062
|
+
if (!align)
|
|
2063
|
+
return '';
|
|
2064
|
+
switch (align) {
|
|
2065
|
+
case 'full':
|
|
2066
|
+
return 'w-full';
|
|
2067
|
+
case 'wide':
|
|
2068
|
+
return 'max-w-7xl mx-auto';
|
|
2069
|
+
case 'center':
|
|
2070
|
+
return 'mx-auto';
|
|
2071
|
+
case 'left':
|
|
2072
|
+
return 'mr-auto';
|
|
2073
|
+
case 'right':
|
|
2074
|
+
return 'ml-auto';
|
|
2075
|
+
default:
|
|
2076
|
+
return '';
|
|
2309
2077
|
}
|
|
2310
|
-
// Use the improved extraction function that handles incomplete cloudflareUrl
|
|
2311
|
-
// This will check cloudflareUrl first, then innerHTML, then regular attributes
|
|
2312
|
-
return extractImageUrlWithFallback(block);
|
|
2313
2078
|
}
|
|
2314
2079
|
/**
|
|
2315
|
-
*
|
|
2316
|
-
* Returns Cloudflare URL if available, otherwise WordPress URL
|
|
2080
|
+
* Map WordPress text alignment to Tailwind classes
|
|
2317
2081
|
*/
|
|
2318
|
-
function
|
|
2319
|
-
|
|
2320
|
-
|
|
2082
|
+
function getTextAlignClasses(textAlign) {
|
|
2083
|
+
if (!textAlign)
|
|
2084
|
+
return '';
|
|
2085
|
+
switch (textAlign) {
|
|
2086
|
+
case 'center':
|
|
2087
|
+
return 'text-center';
|
|
2088
|
+
case 'left':
|
|
2089
|
+
return 'text-left';
|
|
2090
|
+
case 'right':
|
|
2091
|
+
return 'text-right';
|
|
2092
|
+
default:
|
|
2093
|
+
return '';
|
|
2094
|
+
}
|
|
2321
2095
|
}
|
|
2322
2096
|
/**
|
|
2323
|
-
*
|
|
2097
|
+
* Map WordPress font size to Tailwind classes
|
|
2324
2098
|
*/
|
|
2325
|
-
function
|
|
2326
|
-
|
|
2099
|
+
function getFontSizeClasses(fontSize) {
|
|
2100
|
+
if (!fontSize)
|
|
2101
|
+
return '';
|
|
2102
|
+
// Map WordPress font sizes to Tailwind
|
|
2103
|
+
const sizeMap = {
|
|
2104
|
+
'small': 'text-sm',
|
|
2105
|
+
'medium': 'text-base',
|
|
2106
|
+
'large': 'text-lg',
|
|
2107
|
+
'x-large': 'text-xl',
|
|
2108
|
+
'xx-large': 'text-3xl',
|
|
2109
|
+
'xxx-large': 'text-4xl',
|
|
2110
|
+
};
|
|
2111
|
+
return sizeMap[fontSize] || '';
|
|
2327
2112
|
}
|
|
2328
2113
|
/**
|
|
2329
|
-
*
|
|
2114
|
+
* Get container classes based on layout and alignment
|
|
2330
2115
|
*/
|
|
2331
|
-
function
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
|
|
2116
|
+
function getContainerClasses(align, layout) {
|
|
2117
|
+
const alignClass = getAlignmentClasses(align);
|
|
2118
|
+
// If layout is constrained, use container
|
|
2119
|
+
if (layout?.type === 'constrained') {
|
|
2120
|
+
return align === 'full' ? 'w-full' : 'container';
|
|
2121
|
+
}
|
|
2122
|
+
return alignClass || 'container';
|
|
2335
2123
|
}
|
|
2336
2124
|
/**
|
|
2337
|
-
*
|
|
2338
|
-
* Returns React node for rendering
|
|
2125
|
+
* Get spacing classes for sections
|
|
2339
2126
|
*/
|
|
2340
|
-
function
|
|
2341
|
-
|
|
2342
|
-
return text || null;
|
|
2127
|
+
function getSectionSpacingClasses() {
|
|
2128
|
+
return 'py-16 md:py-24';
|
|
2343
2129
|
}
|
|
2344
2130
|
/**
|
|
2345
|
-
*
|
|
2131
|
+
* Get content spacing classes
|
|
2346
2132
|
*/
|
|
2347
|
-
function
|
|
2348
|
-
|
|
2349
|
-
const position = attrs['mediaPosition'] || 'left';
|
|
2350
|
-
return position === 'right' ? 'right' : 'left';
|
|
2133
|
+
function getContentSpacingClasses() {
|
|
2134
|
+
return 'space-y-6';
|
|
2351
2135
|
}
|
|
2352
2136
|
/**
|
|
2353
|
-
*
|
|
2137
|
+
* Build className string from multiple class sources
|
|
2354
2138
|
*/
|
|
2355
|
-
function
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
}
|
|
2361
|
-
return 'center';
|
|
2139
|
+
function buildClassName(...classes) {
|
|
2140
|
+
return classes
|
|
2141
|
+
.filter((cls) => Boolean(cls && cls.trim()))
|
|
2142
|
+
.join(' ')
|
|
2143
|
+
.trim();
|
|
2362
2144
|
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
function extractAlignment(block) {
|
|
2145
|
+
|
|
2146
|
+
const Paragraph = ({ block, context }) => {
|
|
2147
|
+
const content = getBlockTextContent(block);
|
|
2367
2148
|
const attrs = block.attributes || {};
|
|
2368
|
-
const
|
|
2369
|
-
|
|
2370
|
-
|
|
2149
|
+
const textAlign = getTextAlignClasses(attrs['align']);
|
|
2150
|
+
// Check if content contains shortcodes
|
|
2151
|
+
const hasShortcodes = /\[(\w+)/.test(content);
|
|
2152
|
+
if (hasShortcodes && context.registry.shortcodes) {
|
|
2153
|
+
const parts = renderTextWithShortcodes(content, context.registry);
|
|
2154
|
+
// Check if any part is a block-level element (section, div, etc.)
|
|
2155
|
+
// If so, render without wrapping in <p> to avoid DOM nesting violations
|
|
2156
|
+
const isBlockLevelElement = (element) => {
|
|
2157
|
+
if (!React.isValidElement(element)) {
|
|
2158
|
+
return false;
|
|
2159
|
+
}
|
|
2160
|
+
const type = element.type;
|
|
2161
|
+
// Check for block-level HTML elements
|
|
2162
|
+
if (typeof type === 'string' && ['section', 'div', 'article', 'header', 'footer', 'aside', 'nav'].includes(type)) {
|
|
2163
|
+
return true;
|
|
2164
|
+
}
|
|
2165
|
+
// Check if it's React.Fragment - recursively check its children
|
|
2166
|
+
if (type === React.Fragment) {
|
|
2167
|
+
const fragmentProps = element.props;
|
|
2168
|
+
const children = React.Children.toArray(fragmentProps.children);
|
|
2169
|
+
return children.some((child) => isBlockLevelElement(child));
|
|
2170
|
+
}
|
|
2171
|
+
// Check if it's a React component (likely block-level)
|
|
2172
|
+
// Most custom components render block-level content
|
|
2173
|
+
if (typeof type === 'function' || (typeof type === 'object' && type !== null && type !== React.Fragment)) {
|
|
2174
|
+
return true;
|
|
2175
|
+
}
|
|
2176
|
+
return false;
|
|
2177
|
+
};
|
|
2178
|
+
const hasBlockLevelContent = React.Children.toArray(parts).some((part) => isBlockLevelElement(part));
|
|
2179
|
+
if (hasBlockLevelContent) {
|
|
2180
|
+
// Render block-level content without <p> wrapper
|
|
2181
|
+
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: parts });
|
|
2182
|
+
}
|
|
2183
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: parts });
|
|
2371
2184
|
}
|
|
2372
|
-
return '
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
* Extract overlay color from cover block
|
|
2376
|
-
*/
|
|
2377
|
-
function extractOverlayColor(block) {
|
|
2185
|
+
return jsxRuntimeExports.jsx("p", { className: buildClassName('text-gray-700', textAlign), children: content });
|
|
2186
|
+
};
|
|
2187
|
+
const Heading = ({ block, children }) => {
|
|
2378
2188
|
const attrs = block.attributes || {};
|
|
2379
|
-
const
|
|
2380
|
-
|
|
2381
|
-
|
|
2189
|
+
const { level = 2 } = attrs;
|
|
2190
|
+
const content = getBlockTextContent(block);
|
|
2191
|
+
const textAlign = getTextAlignClasses(attrs['textAlign']);
|
|
2192
|
+
const fontSize = getFontSizeClasses(attrs['fontSize']);
|
|
2193
|
+
const Tag = `h${Math.min(Math.max(Number(level) || 2, 1), 6)}`;
|
|
2194
|
+
// Default heading sizes if fontSize not specified
|
|
2195
|
+
const sizeClass = fontSize || (level === 1 ? 'text-4xl' : level === 2 ? 'text-3xl' : level === 3 ? 'text-2xl' : 'text-xl');
|
|
2196
|
+
return (jsxRuntimeExports.jsx(Tag, { className: buildClassName('font-bold text-gray-900', sizeClass, textAlign), children: children ?? content }));
|
|
2197
|
+
};
|
|
2198
|
+
const Image = ({ block }) => {
|
|
2199
|
+
const imageAttrs = getImageAttributes(block);
|
|
2200
|
+
if (!imageAttrs.url)
|
|
2201
|
+
return null;
|
|
2202
|
+
// Use Cloudflare variant URL if it's a Cloudflare image
|
|
2203
|
+
let imageUrl = imageAttrs.url;
|
|
2204
|
+
if (isCloudflareImageUrl(imageUrl)) {
|
|
2205
|
+
const width = imageAttrs.width || 1024;
|
|
2206
|
+
const height = imageAttrs.height;
|
|
2207
|
+
imageUrl = getCloudflareVariantUrl(imageUrl, { width, height });
|
|
2382
2208
|
}
|
|
2383
|
-
return
|
|
2384
|
-
}
|
|
2385
|
-
|
|
2386
|
-
* Extract dim ratio (overlay opacity) from cover block
|
|
2387
|
-
*/
|
|
2388
|
-
function extractDimRatio(block) {
|
|
2209
|
+
return (jsxRuntimeExports.jsx("img", { src: imageUrl, alt: imageAttrs.alt, width: imageAttrs.width, height: imageAttrs.height, className: "w-full h-auto rounded-lg object-cover", style: { maxWidth: '100%', height: 'auto' }, loading: "lazy" }));
|
|
2210
|
+
};
|
|
2211
|
+
const List = ({ block, children }) => {
|
|
2389
2212
|
const attrs = block.attributes || {};
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
*/
|
|
2399
|
-
function extractMinHeight(block) {
|
|
2213
|
+
const { ordered } = attrs;
|
|
2214
|
+
const Tag = ordered ? 'ol' : 'ul';
|
|
2215
|
+
return React.createElement(Tag, { className: 'list-disc pl-6 space-y-2 text-gray-700' }, children);
|
|
2216
|
+
};
|
|
2217
|
+
const ListItem = ({ children }) => {
|
|
2218
|
+
return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: children });
|
|
2219
|
+
};
|
|
2220
|
+
const Group = ({ block, children, context }) => {
|
|
2400
2221
|
const attrs = block.attributes || {};
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2222
|
+
const align = attrs['align'];
|
|
2223
|
+
// Layout can be an object with type property, or nested structure
|
|
2224
|
+
const layout = attrs['layout'];
|
|
2225
|
+
// Extract background color using color mapper
|
|
2226
|
+
const backgroundColor = extractBackgroundColor(block, context);
|
|
2227
|
+
// Determine if this is a section-level group (has alignment) or content-level
|
|
2228
|
+
const isSection = align === 'full' || align === 'wide';
|
|
2229
|
+
const containerClass = getContainerClasses(align, layout);
|
|
2230
|
+
const spacingClass = isSection ? getSectionSpacingClasses() : getContentSpacingClasses();
|
|
2231
|
+
// Ensure container class is always applied for constrained groups
|
|
2232
|
+
const finalContainerClass = layout?.type === 'constrained' && align === 'wide'
|
|
2233
|
+
? 'container'
|
|
2234
|
+
: containerClass;
|
|
2235
|
+
// Build className with background color if present
|
|
2236
|
+
const className = buildClassName(finalContainerClass, spacingClass, backgroundColor // This will be null if no mapping, which is fine
|
|
2237
|
+
);
|
|
2238
|
+
return (jsxRuntimeExports.jsx("div", { className: className, children: children }));
|
|
2239
|
+
};
|
|
2240
|
+
const Columns = ({ block, children }) => {
|
|
2412
2241
|
const attrs = block.attributes || {};
|
|
2413
|
-
const
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
}
|
|
2419
|
-
/**
|
|
2420
|
-
* Extract text alignment from block
|
|
2421
|
-
*/
|
|
2422
|
-
function extractTextAlign(block) {
|
|
2242
|
+
const align = attrs['align'];
|
|
2243
|
+
const alignClass = getAlignmentClasses(align);
|
|
2244
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
|
|
2245
|
+
};
|
|
2246
|
+
const Column = ({ block, children }) => {
|
|
2423
2247
|
const attrs = block.attributes || {};
|
|
2424
|
-
const
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
* Extract font size from block
|
|
2432
|
-
*/
|
|
2433
|
-
function extractFontSize(block) {
|
|
2248
|
+
const width = attrs['width'];
|
|
2249
|
+
// Handle column width (e.g., "50%" becomes flex-basis)
|
|
2250
|
+
const style = width ? { flexBasis: width } : undefined;
|
|
2251
|
+
return (jsxRuntimeExports.jsx("div", { className: "space-y-4", style: style, children: children }));
|
|
2252
|
+
};
|
|
2253
|
+
const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
|
|
2254
|
+
const ButtonBlock = ({ block }) => {
|
|
2434
2255
|
const attrs = block.attributes || {};
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2256
|
+
let url = attrs['url'];
|
|
2257
|
+
let text = attrs['text'];
|
|
2258
|
+
attrs['linkDestination'];
|
|
2259
|
+
// Extract from innerHTML if not in attributes (buttons often store data in innerHTML)
|
|
2260
|
+
if (!url && block.innerHTML) {
|
|
2261
|
+
const linkMatch = block.innerHTML.match(/<a[^>]+href=["']([^"']+)["'][^>]*>([^<]+)<\/a>/i);
|
|
2262
|
+
if (linkMatch) {
|
|
2263
|
+
url = linkMatch[1];
|
|
2264
|
+
text = linkMatch[2] || text;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
// Get text from block content if still missing
|
|
2268
|
+
if (!text) {
|
|
2269
|
+
text = getBlockTextContent(block);
|
|
2270
|
+
}
|
|
2271
|
+
if (!url && !text)
|
|
2443
2272
|
return null;
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2273
|
+
const buttonText = text || 'Learn more';
|
|
2274
|
+
// Handle internal vs external links
|
|
2275
|
+
const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
|
|
2276
|
+
const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
|
|
2277
|
+
return (jsxRuntimeExports.jsx("a", { href: url || '#', className: "inline-flex items-center justify-center rounded-md bg-primary px-6 py-3 text-primary-foreground font-medium hover:bg-primary/90 transition-colors", ...linkProps, children: buttonText }));
|
|
2278
|
+
};
|
|
2279
|
+
const Cover = ({ block, children }) => {
|
|
2280
|
+
const attrs = block.attributes || {};
|
|
2281
|
+
const { url, id, backgroundImage, cloudflareUrl, overlayColor, dimRatio = 0, align = 'full', minHeight, minHeightUnit = 'vh', hasParallax, } = attrs;
|
|
2282
|
+
// Get background image URL from various possible sources
|
|
2283
|
+
// Use the improved extraction function that handles incomplete cloudflareUrl
|
|
2284
|
+
let bgImageUrl = null;
|
|
2285
|
+
// First, try cloudflareUrl if it's valid
|
|
2286
|
+
if (cloudflareUrl && isValidCloudflareUrl(cloudflareUrl)) {
|
|
2287
|
+
bgImageUrl = cloudflareUrl;
|
|
2448
2288
|
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2289
|
+
// If not valid or not found, try regular attributes
|
|
2290
|
+
if (!bgImageUrl) {
|
|
2291
|
+
bgImageUrl = url || backgroundImage || (typeof backgroundImage === 'object' && backgroundImage?.url) || null;
|
|
2292
|
+
}
|
|
2293
|
+
// If still not found, use the fallback extraction (from innerHTML)
|
|
2294
|
+
if (!bgImageUrl) {
|
|
2295
|
+
bgImageUrl = extractImageUrlWithFallback(block);
|
|
2296
|
+
}
|
|
2297
|
+
// Convert to Cloudflare URL variant if it's a Cloudflare image
|
|
2298
|
+
if (bgImageUrl) {
|
|
2299
|
+
if (isCloudflareImageUrl(bgImageUrl)) {
|
|
2300
|
+
// Use full width for cover images
|
|
2301
|
+
bgImageUrl = getCloudflareVariantUrl(bgImageUrl, { width: 1920 });
|
|
2460
2302
|
}
|
|
2461
|
-
// Recursively search nested blocks
|
|
2462
|
-
const nestedTitle = extractTitleFromInnerBlocks(innerBlock);
|
|
2463
|
-
if (nestedTitle)
|
|
2464
|
-
return nestedTitle;
|
|
2465
2303
|
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2304
|
+
// Build alignment classes
|
|
2305
|
+
const alignClass = getAlignmentClasses(align);
|
|
2306
|
+
// Build style object
|
|
2307
|
+
const style = {};
|
|
2308
|
+
if (minHeight) {
|
|
2309
|
+
const minHeightValue = typeof minHeight === 'number' ? minHeight : parseFloat(String(minHeight));
|
|
2310
|
+
style.minHeight = minHeightUnit === 'vh' ? `${minHeightValue}vh` : `${minHeightValue}px`;
|
|
2311
|
+
}
|
|
2312
|
+
if (bgImageUrl) {
|
|
2313
|
+
style.backgroundImage = `url(${bgImageUrl})`;
|
|
2314
|
+
style.backgroundSize = 'cover';
|
|
2315
|
+
style.backgroundPosition = 'center';
|
|
2316
|
+
if (hasParallax) {
|
|
2317
|
+
style.backgroundAttachment = 'fixed';
|
|
2480
2318
|
}
|
|
2481
|
-
// Recursively search nested blocks
|
|
2482
|
-
const nestedSubtitle = extractSubtitleFromInnerBlocks(innerBlock);
|
|
2483
|
-
if (nestedSubtitle)
|
|
2484
|
-
return nestedSubtitle;
|
|
2485
2319
|
}
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2320
|
+
// Calculate overlay opacity
|
|
2321
|
+
const overlayOpacity = typeof dimRatio === 'number' ? dimRatio / 100 : 0;
|
|
2322
|
+
return (jsxRuntimeExports.jsxs("div", { className: buildClassName('relative w-full', alignClass), style: style, children: [overlayOpacity > 0 && (jsxRuntimeExports.jsx("span", { className: "absolute inset-0 z-0", style: {
|
|
2323
|
+
backgroundColor: overlayColor === 'contrast' ? '#000000' : (overlayColor || '#000000'),
|
|
2324
|
+
opacity: overlayOpacity,
|
|
2325
|
+
}, "aria-hidden": "true" })), jsxRuntimeExports.jsx("div", { className: buildClassName('relative z-10', align === 'full' ? 'w-full' : 'container mx-auto px-4'), children: children })] }));
|
|
2326
|
+
};
|
|
2327
|
+
const MediaText = ({ block, children, context }) => {
|
|
2328
|
+
const attrs = block.attributes || {};
|
|
2329
|
+
const { mediaPosition = 'left', verticalAlignment = 'center', imageFill = false, align, } = attrs;
|
|
2330
|
+
// Access innerBlocks to identify media vs content
|
|
2493
2331
|
const innerBlocks = block.innerBlocks || [];
|
|
2494
|
-
// Find
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2332
|
+
// Find media block (image or video)
|
|
2333
|
+
let mediaBlockIndex = innerBlocks.findIndex((b) => b.name === 'core/image' || b.name === 'core/video');
|
|
2334
|
+
// Render children - media-text typically has media as first child, then content
|
|
2335
|
+
const childrenArray = React.Children.toArray(children);
|
|
2336
|
+
let mediaElement = mediaBlockIndex >= 0 && childrenArray[mediaBlockIndex]
|
|
2337
|
+
? childrenArray[mediaBlockIndex]
|
|
2338
|
+
: null;
|
|
2339
|
+
// If no media element from innerBlocks, try to extract image URL
|
|
2340
|
+
if (!mediaElement) {
|
|
2341
|
+
const imageUrl = extractImageUrlWithFallback(block);
|
|
2342
|
+
if (imageUrl) {
|
|
2343
|
+
// Convert to Cloudflare variant if it's a Cloudflare URL
|
|
2344
|
+
// extractImageUrlWithFallback already handles incomplete cloudflareUrl by falling back to innerHTML
|
|
2345
|
+
const finalImageUrl = isCloudflareImageUrl(imageUrl)
|
|
2346
|
+
? getCloudflareVariantUrl(imageUrl, { width: 1024 })
|
|
2347
|
+
: imageUrl;
|
|
2348
|
+
mediaElement = (jsxRuntimeExports.jsx("img", { src: finalImageUrl, alt: "", className: "w-full h-auto rounded-lg shadow-lg object-cover", style: { maxWidth: '100%', height: 'auto' }, loading: "lazy" }));
|
|
2505
2349
|
}
|
|
2506
|
-
return null;
|
|
2507
|
-
};
|
|
2508
|
-
const buttonsBlock = findButtonsBlock(innerBlocks);
|
|
2509
|
-
if (!buttonsBlock || !buttonsBlock.innerBlocks) {
|
|
2510
|
-
return buttons;
|
|
2511
2350
|
}
|
|
2512
|
-
//
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2351
|
+
// Content is all other children
|
|
2352
|
+
const contentElements = childrenArray.filter((_, index) => index !== mediaBlockIndex);
|
|
2353
|
+
// Build alignment classes - ensure proper container width
|
|
2354
|
+
// For 'wide', media-text blocks are typically inside constrained groups (which use 'container' class)
|
|
2355
|
+
// So we should use 'w-full' to fill the parent container, not apply another max-width
|
|
2356
|
+
// Only use 'max-w-7xl' for truly standalone wide blocks (rare case)
|
|
2357
|
+
let alignClass;
|
|
2358
|
+
let spacingClass;
|
|
2359
|
+
if (align === 'full') {
|
|
2360
|
+
alignClass = 'w-full';
|
|
2361
|
+
// Full-width blocks are typically top-level sections, so add section spacing
|
|
2362
|
+
spacingClass = getSectionSpacingClasses();
|
|
2363
|
+
}
|
|
2364
|
+
else if (align === 'wide') {
|
|
2365
|
+
// Wide blocks are usually inside constrained groups (which already have container and spacing)
|
|
2366
|
+
// So just fill the parent container without adding section spacing
|
|
2367
|
+
alignClass = 'w-full';
|
|
2368
|
+
spacingClass = ''; // No section spacing - parent group handles it
|
|
2369
|
+
}
|
|
2370
|
+
else {
|
|
2371
|
+
// Default to contained width (not full width)
|
|
2372
|
+
alignClass = 'container mx-auto';
|
|
2373
|
+
// Contained blocks might be standalone, so add section spacing
|
|
2374
|
+
spacingClass = getSectionSpacingClasses();
|
|
2375
|
+
}
|
|
2376
|
+
// Vertical alignment classes
|
|
2377
|
+
const verticalAlignClass = verticalAlignment === 'top' ? 'items-start' :
|
|
2378
|
+
verticalAlignment === 'bottom' ? 'items-end' :
|
|
2379
|
+
'items-center';
|
|
2380
|
+
// Stack on mobile
|
|
2381
|
+
const stackClass = 'flex-col md:flex-row';
|
|
2382
|
+
// Media position determines order
|
|
2383
|
+
const isMediaRight = mediaPosition === 'right';
|
|
2384
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName(alignClass, spacingClass), children: jsxRuntimeExports.jsxs("div", { className: buildClassName('flex', stackClass, verticalAlignClass, 'gap-6 lg:gap-12', 'w-full'), children: [jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-2' : 'order-1', imageFill ? 'w-full md:w-1/2' : 'w-full md:w-1/2', 'min-w-0', // Allow flex item to shrink below content size
|
|
2385
|
+
'overflow-hidden' // Ensure images don't overflow
|
|
2386
|
+
), children: mediaElement || jsxRuntimeExports.jsx("div", { className: "bg-gray-200 h-64 rounded-lg" }) }), jsxRuntimeExports.jsx("div", { className: buildClassName(isMediaRight ? 'order-1' : 'order-2', 'w-full md:w-1/2', // Explicit width to ensure proper sizing
|
|
2387
|
+
'min-w-0', // Allow flex item to shrink below content size
|
|
2388
|
+
getContentSpacingClasses()), children: contentElements.length > 0 ? contentElements : children })] }) }));
|
|
2389
|
+
};
|
|
2390
|
+
const Fallback = ({ block, children }) => {
|
|
2391
|
+
// Minimal fallback; do not render innerHTML directly in v1 for safety
|
|
2392
|
+
return jsxRuntimeExports.jsx("div", { "data-unknown-block": block.name, children: children });
|
|
2393
|
+
};
|
|
2394
|
+
function createDefaultRegistry(colorMapper) {
|
|
2395
|
+
const renderers = {
|
|
2396
|
+
'core/paragraph': Paragraph,
|
|
2397
|
+
'core/heading': Heading,
|
|
2398
|
+
'core/image': Image,
|
|
2399
|
+
'core/list': List,
|
|
2400
|
+
'core/list-item': ListItem,
|
|
2401
|
+
'core/group': Group,
|
|
2402
|
+
'core/columns': Columns,
|
|
2403
|
+
'core/column': Column,
|
|
2404
|
+
'core/separator': Separator,
|
|
2405
|
+
'core/button': ButtonBlock,
|
|
2406
|
+
'core/buttons': ({ block, children }) => {
|
|
2407
|
+
const attrs = block.attributes || {};
|
|
2408
|
+
const layout = attrs['layout'];
|
|
2409
|
+
const justifyContent = layout?.justifyContent || 'left';
|
|
2410
|
+
const justifyClass = justifyContent === 'center' ? 'justify-center' :
|
|
2411
|
+
justifyContent === 'right' ? 'justify-end' :
|
|
2412
|
+
'justify-start';
|
|
2413
|
+
return jsxRuntimeExports.jsx("div", { className: buildClassName('flex flex-wrap gap-3', justifyClass), children: children });
|
|
2414
|
+
},
|
|
2415
|
+
'core/quote': ({ children }) => jsxRuntimeExports.jsx("blockquote", { className: "border-l-4 pl-4 italic", children: children }),
|
|
2416
|
+
'core/code': ({ block }) => (jsxRuntimeExports.jsx("pre", { className: "bg-gray-100 p-3 rounded text-sm overflow-auto", children: jsxRuntimeExports.jsx("code", { children: getString(block) }) })),
|
|
2417
|
+
'core/preformatted': ({ block }) => jsxRuntimeExports.jsx("pre", { children: getString(block) }),
|
|
2418
|
+
'core/table': ({ children }) => jsxRuntimeExports.jsx("div", { className: "overflow-x-auto", children: jsxRuntimeExports.jsx("table", { className: "table-auto w-full", children: children }) }),
|
|
2419
|
+
'core/table-row': ({ children }) => jsxRuntimeExports.jsx("tr", { children: children }),
|
|
2420
|
+
'core/table-cell': ({ children }) => jsxRuntimeExports.jsx("td", { className: "border px-3 py-2", children: children }),
|
|
2421
|
+
// Cover block - hero sections with background images
|
|
2422
|
+
'core/cover': Cover,
|
|
2423
|
+
// Media & Text block - side-by-side media and content
|
|
2424
|
+
'core/media-text': MediaText,
|
|
2425
|
+
// HTML block - render innerHTML as-is
|
|
2426
|
+
// Note: Shortcodes in HTML blocks are not parsed (they would need to be in text content)
|
|
2427
|
+
'core/html': ({ block }) => {
|
|
2428
|
+
const html = block.innerHTML || '';
|
|
2429
|
+
return jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: html } });
|
|
2430
|
+
},
|
|
2431
|
+
};
|
|
2432
|
+
return {
|
|
2433
|
+
renderers,
|
|
2434
|
+
shortcodes: {}, // Empty by default - apps extend this
|
|
2435
|
+
fallback: Fallback,
|
|
2436
|
+
colorMapper,
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
// Legacy function for backward compatibility - use getBlockTextContent instead
|
|
2440
|
+
function getString(block) {
|
|
2441
|
+
return getBlockTextContent(block);
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
/**
|
|
2445
|
+
* Check if a block matches a pattern
|
|
2446
|
+
*/
|
|
2447
|
+
function matchesPattern(block, pattern) {
|
|
2448
|
+
// Check block name
|
|
2449
|
+
if (block.name !== pattern.name) {
|
|
2450
|
+
return false;
|
|
2451
|
+
}
|
|
2452
|
+
// Check attributes if specified
|
|
2453
|
+
if (pattern.attributes) {
|
|
2454
|
+
const blockAttrs = block.attributes || {};
|
|
2455
|
+
for (const [key, value] of Object.entries(pattern.attributes)) {
|
|
2456
|
+
if (blockAttrs[key] !== value) {
|
|
2457
|
+
return false;
|
|
2532
2458
|
}
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
// Check innerBlocks patterns if specified
|
|
2462
|
+
if (pattern.innerBlocks && pattern.innerBlocks.length > 0) {
|
|
2463
|
+
const blockInnerBlocks = block.innerBlocks || [];
|
|
2464
|
+
// If pattern specifies innerBlocks, check if block has matching innerBlocks
|
|
2465
|
+
for (const innerPattern of pattern.innerBlocks) {
|
|
2466
|
+
// Find at least one matching innerBlock
|
|
2467
|
+
const hasMatch = blockInnerBlocks.some(innerBlock => matchesPattern(innerBlock, innerPattern));
|
|
2468
|
+
if (!hasMatch) {
|
|
2469
|
+
return false;
|
|
2539
2470
|
}
|
|
2540
2471
|
}
|
|
2541
2472
|
}
|
|
2542
|
-
return
|
|
2473
|
+
return true;
|
|
2543
2474
|
}
|
|
2544
2475
|
/**
|
|
2545
|
-
*
|
|
2546
|
-
*
|
|
2547
|
-
* Also checks group blocks for justifyContent in layout
|
|
2548
|
-
* Priority: heading/paragraph textAlign takes precedence over group justifyContent
|
|
2476
|
+
* Find the best matching component mapping for a block
|
|
2477
|
+
* Returns the mapping with highest priority that matches, or null
|
|
2549
2478
|
*/
|
|
2550
|
-
function
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
if (
|
|
2556
|
-
|
|
2557
|
-
const textAlign = attrs['textAlign'];
|
|
2558
|
-
if (textAlign === 'left' || textAlign === 'center' || textAlign === 'right') {
|
|
2559
|
-
return textAlign;
|
|
2560
|
-
}
|
|
2479
|
+
function findMatchingMapping(block, mappings) {
|
|
2480
|
+
// Sort by priority (higher first), then by order in array
|
|
2481
|
+
const sortedMappings = [...mappings].sort((a, b) => {
|
|
2482
|
+
const priorityA = a.priority ?? 0;
|
|
2483
|
+
const priorityB = b.priority ?? 0;
|
|
2484
|
+
if (priorityA !== priorityB) {
|
|
2485
|
+
return priorityB - priorityA; // Higher priority first
|
|
2561
2486
|
}
|
|
2562
|
-
//
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
for (const innerBlock of innerBlocks) {
|
|
2569
|
-
if (innerBlock.name === 'core/group') {
|
|
2570
|
-
const attrs = innerBlock.attributes || {};
|
|
2571
|
-
const layout = attrs['layout'];
|
|
2572
|
-
const justifyContent = layout?.justifyContent;
|
|
2573
|
-
if (justifyContent === 'left')
|
|
2574
|
-
return 'left';
|
|
2575
|
-
if (justifyContent === 'center')
|
|
2576
|
-
return 'center';
|
|
2577
|
-
if (justifyContent === 'right')
|
|
2578
|
-
return 'right';
|
|
2487
|
+
return 0; // Keep original order for same priority
|
|
2488
|
+
});
|
|
2489
|
+
// Find first matching mapping
|
|
2490
|
+
for (const mapping of sortedMappings) {
|
|
2491
|
+
if (matchesPattern(block, mapping.pattern)) {
|
|
2492
|
+
return mapping;
|
|
2579
2493
|
}
|
|
2580
2494
|
}
|
|
2581
2495
|
return null;
|
|
2582
2496
|
}
|
|
2497
|
+
|
|
2583
2498
|
/**
|
|
2584
|
-
*
|
|
2585
|
-
*
|
|
2499
|
+
* Create an enhanced registry that supports pattern-based component mapping
|
|
2500
|
+
*
|
|
2501
|
+
* This combines the default registry (for fallback) with app-specific component mappings.
|
|
2502
|
+
* When a block matches a pattern, it uses the mapped component. Otherwise, it falls back
|
|
2503
|
+
* to the default renderer.
|
|
2504
|
+
*
|
|
2505
|
+
* @param mappings - Array of component mappings with patterns
|
|
2506
|
+
* @param baseRegistry - Optional base registry (defaults to createDefaultRegistry())
|
|
2507
|
+
* @returns Enhanced registry with pattern matching capabilities
|
|
2508
|
+
*
|
|
2509
|
+
* @example
|
|
2510
|
+
* ```ts
|
|
2511
|
+
* const mappings: ComponentMapping[] = [
|
|
2512
|
+
* {
|
|
2513
|
+
* pattern: { name: 'core/cover' },
|
|
2514
|
+
* component: HomeHeroSection,
|
|
2515
|
+
* extractProps: (block) => ({
|
|
2516
|
+
* backgroundImage: extractBackgroundImage(block),
|
|
2517
|
+
* title: extractTitle(block),
|
|
2518
|
+
* }),
|
|
2519
|
+
* wrapper: SectionWrapper,
|
|
2520
|
+
* },
|
|
2521
|
+
* ];
|
|
2522
|
+
*
|
|
2523
|
+
* const registry = createEnhancedRegistry(mappings);
|
|
2524
|
+
* ```
|
|
2586
2525
|
*/
|
|
2587
|
-
function
|
|
2588
|
-
|
|
2589
|
-
|
|
2526
|
+
function createEnhancedRegistry(mappings = [], baseRegistry, colorMapper) {
|
|
2527
|
+
const base = baseRegistry || createDefaultRegistry(colorMapper);
|
|
2528
|
+
// Create enhanced renderers that check patterns first
|
|
2529
|
+
const enhancedRenderers = {
|
|
2530
|
+
...base.renderers,
|
|
2531
|
+
};
|
|
2532
|
+
// Override renderers for blocks that have mappings
|
|
2533
|
+
// We need to check patterns at render time, so we create a wrapper renderer
|
|
2534
|
+
const createPatternRenderer = (blockName) => {
|
|
2535
|
+
return (props) => {
|
|
2536
|
+
const { block, context } = props;
|
|
2537
|
+
// Find matching mapping
|
|
2538
|
+
const mapping = findMatchingMapping(block, mappings);
|
|
2539
|
+
if (mapping) {
|
|
2540
|
+
// Extract props from block
|
|
2541
|
+
const componentProps = mapping.extractProps(block, context);
|
|
2542
|
+
// Render component
|
|
2543
|
+
const Component = mapping.component;
|
|
2544
|
+
const content = jsxRuntimeExports.jsx(Component, { ...componentProps });
|
|
2545
|
+
// Wrap with wrapper if provided
|
|
2546
|
+
if (mapping.wrapper) {
|
|
2547
|
+
const Wrapper = mapping.wrapper;
|
|
2548
|
+
return jsxRuntimeExports.jsx(Wrapper, { block: block, children: content });
|
|
2549
|
+
}
|
|
2550
|
+
return content;
|
|
2551
|
+
}
|
|
2552
|
+
// Fall back to default renderer
|
|
2553
|
+
const defaultRenderer = base.renderers[blockName] || base.fallback;
|
|
2554
|
+
return defaultRenderer(props);
|
|
2555
|
+
};
|
|
2556
|
+
};
|
|
2557
|
+
// For each mapping, override the renderer for that block name
|
|
2558
|
+
for (const mapping of mappings) {
|
|
2559
|
+
const blockName = mapping.pattern.name;
|
|
2560
|
+
if (blockName) {
|
|
2561
|
+
enhancedRenderers[blockName] = createPatternRenderer(blockName);
|
|
2562
|
+
}
|
|
2590
2563
|
}
|
|
2591
|
-
|
|
2592
|
-
const
|
|
2593
|
-
|
|
2564
|
+
// Create matchBlock function
|
|
2565
|
+
const matchBlock = (block) => {
|
|
2566
|
+
return findMatchingMapping(block, mappings);
|
|
2567
|
+
};
|
|
2594
2568
|
return {
|
|
2595
|
-
|
|
2596
|
-
|
|
2569
|
+
...base,
|
|
2570
|
+
renderers: enhancedRenderers,
|
|
2571
|
+
mappings,
|
|
2572
|
+
matchBlock,
|
|
2573
|
+
// Use provided colorMapper or inherit from base registry
|
|
2574
|
+
colorMapper: colorMapper || base.colorMapper,
|
|
2597
2575
|
};
|
|
2598
2576
|
}
|
|
2577
|
+
|
|
2578
|
+
const WPContent = ({ blocks, registry, className, page }) => {
|
|
2579
|
+
if (!Array.isArray(blocks)) {
|
|
2580
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2581
|
+
// eslint-disable-next-line no-console
|
|
2582
|
+
console.warn('WPContent: invalid blocks prop');
|
|
2583
|
+
}
|
|
2584
|
+
return null;
|
|
2585
|
+
}
|
|
2586
|
+
if (!registry || !registry.renderers) {
|
|
2587
|
+
throw new Error('WPContent: registry is required');
|
|
2588
|
+
}
|
|
2589
|
+
const ast = parseGutenbergBlocks(blocks);
|
|
2590
|
+
return (jsxRuntimeExports.jsx("div", { className: className, children: renderNodes(ast, registry, undefined, page) }));
|
|
2591
|
+
};
|
|
2592
|
+
|
|
2599
2593
|
/**
|
|
2600
|
-
*
|
|
2594
|
+
* Hero logic:
|
|
2595
|
+
* - If the content contains a [HEROSECTION] shortcode (case-insensitive), do NOT auto-hero.
|
|
2596
|
+
* - Else, if the page has featured media, render a hero section using the image as background.
|
|
2601
2597
|
*/
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
// Check if innerHTML contains an iframe
|
|
2608
|
-
if (innerBlock.innerHTML.includes('<iframe')) {
|
|
2609
|
-
return innerBlock.innerHTML;
|
|
2610
|
-
}
|
|
2611
|
-
}
|
|
2612
|
-
// Recursively search nested blocks
|
|
2613
|
-
if (innerBlock.innerBlocks) {
|
|
2614
|
-
const nestedVideo = extractVideoIframeFromInnerBlocks(innerBlock);
|
|
2615
|
-
if (nestedVideo)
|
|
2616
|
-
return nestedVideo;
|
|
2598
|
+
const WPPage = ({ page, registry, className }) => {
|
|
2599
|
+
if (!page || !Array.isArray(page.blocks)) {
|
|
2600
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2601
|
+
// eslint-disable-next-line no-console
|
|
2602
|
+
console.warn('WPPage: invalid page prop');
|
|
2617
2603
|
}
|
|
2604
|
+
return null;
|
|
2605
|
+
}
|
|
2606
|
+
if (!registry || !registry.renderers) {
|
|
2607
|
+
throw new Error('WPPage: registry is required');
|
|
2608
|
+
}
|
|
2609
|
+
const hasHeroShortcode = React.useMemo(() => detectHeroShortcode(page.blocks), [page.blocks]);
|
|
2610
|
+
const featured = getFeaturedImage(page);
|
|
2611
|
+
return (jsxRuntimeExports.jsxs("article", { className: className, children: [!hasHeroShortcode && featured && (jsxRuntimeExports.jsx(HeroFromFeatured, { featured: featured, title: page.title?.rendered })), jsxRuntimeExports.jsx(WPContent, { blocks: page.blocks, registry: registry, page: page })] }));
|
|
2612
|
+
};
|
|
2613
|
+
function detectHeroShortcode(blocks) {
|
|
2614
|
+
for (const block of blocks) {
|
|
2615
|
+
const html = (block.innerHTML || '').toLowerCase();
|
|
2616
|
+
if (html.includes('[herosection]'))
|
|
2617
|
+
return true;
|
|
2618
|
+
// Check if this is a cover block (which is a hero section)
|
|
2619
|
+
if (block.name === 'core/cover')
|
|
2620
|
+
return true;
|
|
2621
|
+
if (block.innerBlocks?.length && detectHeroShortcode(block.innerBlocks))
|
|
2622
|
+
return true;
|
|
2618
2623
|
}
|
|
2624
|
+
return false;
|
|
2625
|
+
}
|
|
2626
|
+
function getFeaturedImage(page) {
|
|
2627
|
+
const fm = page._embedded?.['wp:featuredmedia'];
|
|
2628
|
+
if (Array.isArray(fm) && fm.length > 0)
|
|
2629
|
+
return fm[0];
|
|
2619
2630
|
return null;
|
|
2620
2631
|
}
|
|
2632
|
+
const HeroFromFeatured = ({ featured, title }) => {
|
|
2633
|
+
const url = featured.source_url;
|
|
2634
|
+
if (!url)
|
|
2635
|
+
return null;
|
|
2636
|
+
return (jsxRuntimeExports.jsx("section", { className: "w-full h-[40vh] min-h-[280px] flex items-end bg-cover bg-center", style: { backgroundImage: `url(${url})` }, "aria-label": featured.alt_text || title || 'Hero', children: jsxRuntimeExports.jsx("div", { className: "container mx-auto px-4 py-8 bg-gradient-to-t from-black/50 to-transparent w-full", children: title && jsxRuntimeExports.jsx("h1", { className: "text-white text-4xl font-bold drop-shadow", children: title }) }) }));
|
|
2637
|
+
};
|
|
2638
|
+
|
|
2639
|
+
class WPErrorBoundary extends React.Component {
|
|
2640
|
+
constructor(props) {
|
|
2641
|
+
super(props);
|
|
2642
|
+
this.state = { hasError: false };
|
|
2643
|
+
}
|
|
2644
|
+
static getDerivedStateFromError() {
|
|
2645
|
+
return { hasError: true };
|
|
2646
|
+
}
|
|
2647
|
+
componentDidCatch(error) {
|
|
2648
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2649
|
+
// eslint-disable-next-line no-console
|
|
2650
|
+
console.error('WPErrorBoundary caught error:', error);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
render() {
|
|
2654
|
+
if (this.state.hasError) {
|
|
2655
|
+
return this.props.fallback ?? null;
|
|
2656
|
+
}
|
|
2657
|
+
return this.props.children;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2621
2660
|
|
|
2622
2661
|
/**
|
|
2623
2662
|
* Convert image URL with optional Cloudflare variant transformation
|
|
@@ -2712,6 +2751,7 @@ exports.convertImageUrls = convertImageUrls;
|
|
|
2712
2751
|
exports.createDefaultRegistry = createDefaultRegistry;
|
|
2713
2752
|
exports.createEnhancedRegistry = createEnhancedRegistry;
|
|
2714
2753
|
exports.extractAlignment = extractAlignment;
|
|
2754
|
+
exports.extractBackgroundColor = extractBackgroundColor;
|
|
2715
2755
|
exports.extractBackgroundImage = extractBackgroundImage;
|
|
2716
2756
|
exports.extractButtonsFromInnerBlocks = extractButtonsFromInnerBlocks;
|
|
2717
2757
|
exports.extractContent = extractContent;
|