Merge fix/editor-parity into release/editor-parity (on top of captcha + Font Awesome)
This commit is contained in:
commit
ab7a10073b
30 files changed
+1067
-31
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { HeroSimple } from './HeroSimple';
|
||||
|
||||
// Exported section tag captured BEFORE the shorthand/longhand fix; must stay byte-identical.
|
||||
const toHtml = (HeroSimple as any).toHtml;
|
||||
const cases: Array<[any, string]> = [
|
||||
[{"bgType":"gradient"}, "<section style=\"background:linear-gradient(135deg, var(--wsb-primary), var(--wsb-secondary));min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"color","bgColor":"#123456"}, "<section style=\"background:#123456;min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"image","bgImage":"a.jpg"}, "<section style=\"background-image:url('a.jpg');background-size:cover;background-position:center;min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"image","bgImage":"a.jpg","bgPosition":"top"}, "<section style=\"background-image:url('a.jpg');background-size:cover;background-position:top;min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"image"}, "<section style=\"background-size:cover;background-position:center;min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"video","bgVideo":"v.mp4"}, "<section style=\"background:var(--wsb-text);min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px\">"],
|
||||
[{"bgType":"gradient","style":{"backgroundColor":"red"}}, "<section style=\"background:linear-gradient(135deg, var(--wsb-primary), var(--wsb-secondary));min-height:500px;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:60px 20px;background-color:red\">"],
|
||||
];
|
||||
|
||||
describe('HeroSimple.toHtml background output is unchanged by the longhand fix', () => {
|
||||
test.each(cases)('%j', (props, expected) => {
|
||||
const tag = toHtml(props, '').html.match(/<section[^>]*>/)[0];
|
||||
expect(tag).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, test, expect, afterEach } from 'vitest';
|
||||
import { renderEditorHarness, EditorHarness } from '../../test-utils/editorHarness';
|
||||
import { HeroSimple } from './HeroSimple';
|
||||
|
||||
// The canvas render must lay the <section> out exactly like toHtml (published is the source of
|
||||
// truth): same declarations, `style` LAST so style.minHeight / padding win over the minHeight prop.
|
||||
const node = (type: string, props: Record<string, unknown>, nodes: string[] = [], extra: Record<string, unknown> = {}) => ({
|
||||
type: { resolvedName: type }, isCanvas: type === 'Container', props, displayName: type, custom: {}, hidden: false, nodes, linkedNodes: {}, ...extra,
|
||||
});
|
||||
let h: EditorHarness | null = null;
|
||||
afterEach(() => { h?.unmount(); h = null; });
|
||||
|
||||
const cases: Record<string, any>[] = [
|
||||
{ minHeight: '600px', style: { minHeight: '480px' } },
|
||||
{ minHeight: '300px', style: {} },
|
||||
{ minHeight: '600px', style: { padding: '10px 5px', display: 'block' } },
|
||||
];
|
||||
|
||||
describe('HeroSimple canvas render == export', () => {
|
||||
test.each(cases)('%j', (props) => {
|
||||
h = renderEditorHarness({
|
||||
initialState: JSON.stringify({
|
||||
ROOT: node('Container', { tag: 'div', style: {} }, ['hero']),
|
||||
hero: node('HeroSimple', props, [], { parent: 'ROOT' }),
|
||||
}),
|
||||
});
|
||||
const sec = h.container.querySelector('section') as HTMLElement;
|
||||
const html = (HeroSimple as any).toHtml(props, '').html.match(/<section[^>]*>/)[0];
|
||||
const exp = document.createElement('div');
|
||||
exp.innerHTML = html + '</section>';
|
||||
const e = (exp.firstElementChild as HTMLElement).style;
|
||||
for (const p of ['minHeight', 'padding', 'display', 'alignItems', 'overflow', 'position'] as const) {
|
||||
expect(sec.style[p], p).toBe(e[p]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -49,6 +49,24 @@ function buildBackground(props: HeroProps): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Background style keys for the hero section. Emits EITHER the `background`
|
||||
* shorthand (color/gradient/video) OR the image longhands -- never the
|
||||
* shorthand together with a longhand that may be undefined. React assigns ''
|
||||
* for undefined style values on the initial render, and in Chromium assigning
|
||||
* a background longhand '' AFTER the `background` shorthand wipes the
|
||||
* shorthand's gradient (background-image -> none), leaving the editor canvas
|
||||
* hero blank. jsdom does not reproduce this; see scripts/e2e-background.mjs.
|
||||
*/
|
||||
function heroBackgroundStyle(props: HeroProps): React.CSSProperties {
|
||||
if (props.bgType !== 'image') return { background: buildBackground(props) };
|
||||
return {
|
||||
...(props.bgImage ? { backgroundImage: `url('${props.bgImage}')` } : {}),
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: cssValue(props.bgPosition) || 'center',
|
||||
};
|
||||
}
|
||||
|
||||
export const HeroSimple: UserComponent<HeroProps> = ({
|
||||
heading = 'Build Something Amazing',
|
||||
subtitle = 'Create beautiful websites without writing a single line of code.',
|
||||
@@ -78,10 +96,6 @@ export const HeroSimple: UserComponent<HeroProps> = ({
|
||||
}) => {
|
||||
const { connectors: { connect, drag } } = useNode();
|
||||
|
||||
const bg = buildBackground({
|
||||
bgType, bgColor, bgGradientFrom, bgGradientTo, bgGradientAngle, bgImage,
|
||||
} as HeroProps);
|
||||
|
||||
const justifyMap = { top: 'flex-start', center: 'center', bottom: 'flex-end' };
|
||||
|
||||
const effectiveCtas = normalizeCtas({ ctas, buttonText, buttonHref, secondaryButtonText, secondaryButtonHref });
|
||||
@@ -95,19 +109,19 @@ export const HeroSimple: UserComponent<HeroProps> = ({
|
||||
<section
|
||||
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||
id={anchorId || undefined}
|
||||
// Same declaration ORDER as toHtml (published output is the source of truth):
|
||||
// computed defaults first, the node's own `style` last so style.minHeight /
|
||||
// padding / display ... win over the `minHeight` prop and the built-ins.
|
||||
style={{
|
||||
...style,
|
||||
background: bgType !== 'image' ? bg : undefined,
|
||||
backgroundImage: bgType === 'image' && bgImage ? `url('${bgImage}')` : undefined,
|
||||
backgroundSize: bgType === 'image' ? 'cover' : undefined,
|
||||
backgroundPosition: bgType === 'image' ? (cssValue(bgPosition) || 'center') : undefined,
|
||||
minHeight: minHeight === '100vh' ? '100vh' : minHeight,
|
||||
...heroBackgroundStyle({ bgType, bgColor, bgGradientFrom, bgGradientTo, bgGradientAngle, bgImage, bgPosition } as HeroProps),
|
||||
minHeight: minHeight || '500px',
|
||||
display: 'flex',
|
||||
alignItems: justifyMap[verticalAlign] || 'center',
|
||||
justifyContent: 'center',
|
||||
position: 'relative',
|
||||
overflow: 'hidden',
|
||||
padding: '60px 20px',
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
{/* Video background */}
|
||||
@@ -205,14 +219,10 @@ HeroSimple.craft = {
|
||||
/* ---------- HTML export ---------- */
|
||||
|
||||
(HeroSimple as any).toHtml = (props: HeroProps, _childrenHtml: string) => {
|
||||
const bg = buildBackground(props);
|
||||
const justifyMap: Record<string, string> = { top: 'flex-start', center: 'center', bottom: 'flex-end' };
|
||||
|
||||
const sectionStyle = cssPropsToString({
|
||||
background: props.bgType !== 'image' ? bg : undefined,
|
||||
backgroundImage: props.bgType === 'image' && props.bgImage ? `url('${props.bgImage}')` : undefined,
|
||||
backgroundSize: props.bgType === 'image' ? 'cover' : undefined,
|
||||
backgroundPosition: props.bgType === 'image' ? (cssValue(props.bgPosition) || 'center') : undefined,
|
||||
...heroBackgroundStyle(props),
|
||||
minHeight: props.minHeight || '500px',
|
||||
display: 'flex',
|
||||
alignItems: justifyMap[props.verticalAlign || 'center'],
|
||||
|
||||
Reference in new issue
Block a user