@marvalt/wparser 0.1.29 → 0.1.31
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 +74 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +74 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/registry/defaultRegistry.d.ts.map +1 -1
- package/dist/utils/blockExtractors.d.ts +9 -0
- package/dist/utils/blockExtractors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2059,6 +2059,38 @@ function extractBackgroundColor(block, context) {
|
|
|
2059
2059
|
// Fallback: return null (no background applied)
|
|
2060
2060
|
return null;
|
|
2061
2061
|
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Extract and map text color from block attributes
|
|
2064
|
+
* Uses colorMapper from context to convert WordPress theme colors to app CSS classes
|
|
2065
|
+
*
|
|
2066
|
+
* @param block - WordPress block to extract text color from
|
|
2067
|
+
* @param context - Render context containing optional colorMapper
|
|
2068
|
+
* @returns CSS class string (e.g., 'text-white') or null if no mapping
|
|
2069
|
+
*/
|
|
2070
|
+
function extractTextColor(block, context) {
|
|
2071
|
+
const attrs = block.attributes || {};
|
|
2072
|
+
const wpColorName = attrs['textColor'] || attrs['text'];
|
|
2073
|
+
if (!wpColorName || typeof wpColorName !== 'string') {
|
|
2074
|
+
return null;
|
|
2075
|
+
}
|
|
2076
|
+
// Use colorMapper from context if available
|
|
2077
|
+
// Note: colorMapper might return combined classes like "bg-gray-900 text-white"
|
|
2078
|
+
// We'll extract just the text color part, or create a separate text color mapping
|
|
2079
|
+
if (context.colorMapper) {
|
|
2080
|
+
const mapped = context.colorMapper(wpColorName);
|
|
2081
|
+
if (mapped) {
|
|
2082
|
+
// If the mapped class includes text color (e.g., "bg-gray-900 text-white"),
|
|
2083
|
+
// extract just the text color part
|
|
2084
|
+
const textColorMatch = mapped.match(/\btext-\S+/);
|
|
2085
|
+
if (textColorMatch) {
|
|
2086
|
+
return textColorMatch[0];
|
|
2087
|
+
}
|
|
2088
|
+
// If no text color in the mapped class, try to infer from the color name
|
|
2089
|
+
// For now, return null and let the app handle it via a separate text color mapper
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
return null;
|
|
2093
|
+
}
|
|
2062
2094
|
/**
|
|
2063
2095
|
* Extract spacer height from block attributes or innerHTML
|
|
2064
2096
|
* Returns height in pixels, or null if not found
|
|
@@ -2270,10 +2302,35 @@ const List = ({ block, children, context }) => {
|
|
|
2270
2302
|
const { ordered } = attrs;
|
|
2271
2303
|
const Tag = ordered ? 'ol' : 'ul';
|
|
2272
2304
|
const spacing = getSpacing(context.spacingConfig || context.registry.spacingConfig, 'list', 'my-6');
|
|
2273
|
-
|
|
2305
|
+
// Extract text color if specified
|
|
2306
|
+
const textColor = extractTextColor(block, context);
|
|
2307
|
+
// Default text color if none specified
|
|
2308
|
+
const textColorClass = textColor || 'text-gray-700';
|
|
2309
|
+
return React.createElement(Tag, { className: buildClassName('list-disc pl-6 space-y-2', textColorClass, spacing) }, children);
|
|
2274
2310
|
};
|
|
2275
|
-
const ListItem = ({ children }) => {
|
|
2276
|
-
|
|
2311
|
+
const ListItem = ({ block, children }) => {
|
|
2312
|
+
// List items store their content in innerHTML (e.g., "<li>Text<br>More text</li>")
|
|
2313
|
+
// We need to extract the content from inside the <li> tag and render it properly
|
|
2314
|
+
let content = null;
|
|
2315
|
+
if (block.innerHTML) {
|
|
2316
|
+
// Extract content from innerHTML - remove the outer <li> tags
|
|
2317
|
+
// Pattern: <li>content</li> or <li>content<br>more</li>
|
|
2318
|
+
const liMatch = block.innerHTML.match(/<li[^>]*>(.*?)<\/li>/is);
|
|
2319
|
+
if (liMatch && liMatch[1]) {
|
|
2320
|
+
const innerContent = liMatch[1].trim();
|
|
2321
|
+
if (innerContent) {
|
|
2322
|
+
// Use dangerouslySetInnerHTML to properly render HTML content including <br> tags and entities
|
|
2323
|
+
// This is safe because we're only rendering content from WordPress (trusted source)
|
|
2324
|
+
content = jsxRuntimeExports.jsx("span", { dangerouslySetInnerHTML: { __html: innerContent } });
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
// If we have both innerHTML content and children (innerBlocks), combine them
|
|
2329
|
+
if (content && children && React.Children.count(children) > 0) {
|
|
2330
|
+
return (jsxRuntimeExports.jsxs("li", { className: "text-gray-700", children: [content, children] }));
|
|
2331
|
+
}
|
|
2332
|
+
// Return content from innerHTML if available, otherwise use children
|
|
2333
|
+
return jsxRuntimeExports.jsx("li", { className: "text-gray-700", children: content || children });
|
|
2277
2334
|
};
|
|
2278
2335
|
const Group = ({ block, children, context }) => {
|
|
2279
2336
|
const attrs = block.attributes || {};
|
|
@@ -2305,15 +2362,17 @@ const Columns = ({ block, children }) => {
|
|
|
2305
2362
|
const alignClass = getAlignmentClasses(align);
|
|
2306
2363
|
return (jsxRuntimeExports.jsx("div", { className: buildClassName('grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-12', alignClass), children: children }));
|
|
2307
2364
|
};
|
|
2308
|
-
const Column = ({ block, children }) => {
|
|
2365
|
+
const Column = ({ block, children, context }) => {
|
|
2309
2366
|
const attrs = block.attributes || {};
|
|
2310
2367
|
const width = attrs['width'];
|
|
2368
|
+
// Extract background color using color mapper
|
|
2369
|
+
const backgroundColor = extractBackgroundColor(block, context);
|
|
2311
2370
|
// Handle column width (e.g., "50%" becomes flex-basis)
|
|
2312
2371
|
const style = width ? { flexBasis: width } : undefined;
|
|
2313
|
-
return (jsxRuntimeExports.jsx("div", { className:
|
|
2372
|
+
return (jsxRuntimeExports.jsx("div", { className: buildClassName('space-y-4 p-6 rounded-lg', backgroundColor), style: style, children: children }));
|
|
2314
2373
|
};
|
|
2315
2374
|
const Separator = () => jsxRuntimeExports.jsx("hr", { className: "border-gray-200 my-8" });
|
|
2316
|
-
const ButtonBlock = ({ block }) => {
|
|
2375
|
+
const ButtonBlock = ({ block, context }) => {
|
|
2317
2376
|
const attrs = block.attributes || {};
|
|
2318
2377
|
let url = attrs['url'];
|
|
2319
2378
|
let text = attrs['text'];
|
|
@@ -2333,10 +2392,17 @@ const ButtonBlock = ({ block }) => {
|
|
|
2333
2392
|
if (!url && !text)
|
|
2334
2393
|
return null;
|
|
2335
2394
|
const buttonText = text || 'Learn more';
|
|
2395
|
+
// Extract background and text colors from button attributes
|
|
2396
|
+
const backgroundColor = extractBackgroundColor(block, context);
|
|
2397
|
+
const textColor = extractTextColor(block, context);
|
|
2398
|
+
// Build button classes - use extracted colors or defaults
|
|
2399
|
+
const bgClass = backgroundColor || 'bg-primary';
|
|
2400
|
+
const textClass = textColor || 'text-primary-foreground';
|
|
2401
|
+
const hoverClass = backgroundColor ? 'hover:opacity-90' : 'hover:bg-primary/90';
|
|
2336
2402
|
// Handle internal vs external links
|
|
2337
2403
|
const isExternal = url && (url.startsWith('http://') || url.startsWith('https://'));
|
|
2338
2404
|
const linkProps = isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {};
|
|
2339
|
-
return (jsxRuntimeExports.jsx("a", { href: url || '#', className:
|
|
2405
|
+
return (jsxRuntimeExports.jsx("a", { href: url || '#', className: buildClassName('inline-flex items-center justify-center rounded-md px-6 py-3 font-medium transition-colors', bgClass, textClass, hoverClass), ...linkProps, children: buttonText }));
|
|
2340
2406
|
};
|
|
2341
2407
|
const Cover = ({ block, children }) => {
|
|
2342
2408
|
const attrs = block.attributes || {};
|
|
@@ -2842,6 +2908,7 @@ exports.extractSpacerHeight = extractSpacerHeight;
|
|
|
2842
2908
|
exports.extractSubtitleFromInnerBlocks = extractSubtitleFromInnerBlocks;
|
|
2843
2909
|
exports.extractTextAlign = extractTextAlign;
|
|
2844
2910
|
exports.extractTextAlignFromInnerBlocks = extractTextAlignFromInnerBlocks;
|
|
2911
|
+
exports.extractTextColor = extractTextColor;
|
|
2845
2912
|
exports.extractTextFromHTML = extractTextFromHTML;
|
|
2846
2913
|
exports.extractTitle = extractTitle;
|
|
2847
2914
|
exports.extractTitleFromInnerBlocks = extractTitleFromInnerBlocks;
|