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
@@ -154,3 +154,10 @@ describe('Heading.toHtml inline rich text (#46)', () => {
|
||||
test('Heading default colour is the text token', () => {
|
||||
expect((Heading as any).craft.props.style.color).toBe('var(--wsb-text)');
|
||||
});
|
||||
|
||||
describe('Heading.toHtml newlines (canvas parity)', () => {
|
||||
test('plain text newlines become <br>, like the editor canvas', () => {
|
||||
const { html } = (Heading as any).toHtml({ text: 'a\nb', level: 'h2' }, '');
|
||||
expect(html).toContain('a<br>b');
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { escapeHtml } from '../../utils/escape';
|
||||
import { resolveInlineHtml } from '../../utils/inline-html';
|
||||
import { resolveInlineHtml, textToInlineHtml } from '../../utils/inline-html';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useInlineEditable } from './useInlineEditable';
|
||||
|
||||
@@ -102,7 +101,7 @@ Heading.craft = {
|
||||
|
||||
(Heading as any).toHtml = (props: HeadingProps, _childrenHtml: string) => {
|
||||
const tag = sanitizeHeadingLevel(props.level);
|
||||
const safeText = resolveInlineHtml(props.text, props.html) ?? escapeHtml(props.text || '');
|
||||
const safeText = resolveInlineHtml(props.text, props.html) ?? textToInlineHtml(props.text || '');
|
||||
const styleStr = cssPropsToString(props.style);
|
||||
return { html: `<${tag}${styleStr ? ` style="${styleStr}"` : ''}>${safeText}</${tag}>` };
|
||||
};
|
||||
@@ -117,3 +117,10 @@ describe('TextBlock.toHtml design tokens (#44)', () => {
|
||||
for (const hex of ["#3f3f46"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TextBlock.toHtml newlines (canvas parity)', () => {
|
||||
test('plain text newlines become <br>, like the editor canvas (textToInlineHtml)', () => {
|
||||
const { html } = toHtml({ text: 'a\n\nb <i>' }, '');
|
||||
expect(html).toBe('<p>a<br><br>b <i></p>');
|
||||
});
|
||||
});
|
||||
@@ -2,8 +2,7 @@ import React, { CSSProperties } from 'react';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { escapeHtml } from '../../utils/escape';
|
||||
import { resolveInlineHtml } from '../../utils/inline-html';
|
||||
import { resolveInlineHtml, textToInlineHtml } from '../../utils/inline-html';
|
||||
import { useInlineEditable } from './useInlineEditable';
|
||||
|
||||
interface TextBlockProps {
|
||||
@@ -94,6 +93,6 @@ TextBlock.craft = {
|
||||
|
||||
(TextBlock as any).toHtml = (props: TextBlockProps, _childrenHtml: string) => {
|
||||
const styleStr = cssPropsToString(props.style);
|
||||
const escapedText = resolveInlineHtml(props.text, props.html) ?? escapeHtml(props.text || '');
|
||||
const escapedText = resolveInlineHtml(props.text, props.html) ?? textToInlineHtml(props.text || '');
|
||||
return { html: `<p${styleStr ? ` style="${styleStr}"` : ''}>${escapedText}</p>` };
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, test, expect, afterEach } from 'vitest';
|
||||
import { renderEditorHarness, EditorHarness } from '../../test-utils/editorHarness';
|
||||
|
||||
// The 40px min-height is an editor-only DROP ZONE for EMPTY containers. A container that has
|
||||
// content must lay out like the published page (no injected min-height).
|
||||
const node = (type: string, props: Record<string, unknown>, nodes: string[] = [], extra: Record<string, unknown> = {}) => ({
|
||||
type: { resolvedName: type }, isCanvas: type === 'Container' || type === 'Text', props, displayName: type, custom: {}, hidden: false, nodes, linkedNodes: {}, ...extra,
|
||||
});
|
||||
let h: EditorHarness | null = null;
|
||||
afterEach(() => { h?.unmount(); h = null; });
|
||||
const mount = (inner: Record<string, any>, withChild: boolean) => {
|
||||
h = renderEditorHarness({
|
||||
initialState: JSON.stringify({
|
||||
ROOT: node('Container', { tag: 'div', style: {} }, ['c1']),
|
||||
c1: node('Container', { tag: 'section', ...inner }, withChild ? ['t1'] : [], { parent: 'ROOT' }),
|
||||
...(withChild ? { t1: node('TextBlock', { text: 'hi', style: {} }, [], { parent: 'c1' }) } : {}),
|
||||
}),
|
||||
});
|
||||
return h.container.querySelector('section') as HTMLElement;
|
||||
};
|
||||
|
||||
describe('Container empty-only drop zone', () => {
|
||||
test('empty container keeps the 40px drop zone', () => {
|
||||
expect(mount({ style: {} }, false).style.minHeight).toBe('40px');
|
||||
});
|
||||
test('non-empty container does NOT get an injected min-height', () => {
|
||||
expect(mount({ style: {} }, true).style.minHeight).toBe('');
|
||||
});
|
||||
test('an explicit style.minHeight always wins', () => {
|
||||
expect(mount({ style: { minHeight: '100px' } }, true).style.minHeight).toBe('100px');
|
||||
expect(mount({ style: { minHeight: '100px' } }, false).style.minHeight).toBe('100px');
|
||||
});
|
||||
});
|
||||
|
||||
describe('data-wsb-dropzone marker (harness hook)', () => {
|
||||
test('set only while the drop-zone min-height is the one applied', () => {
|
||||
expect(mount({ style: {} }, false).hasAttribute('data-wsb-dropzone')).toBe(true);
|
||||
expect(mount({ style: {} }, true).hasAttribute('data-wsb-dropzone')).toBe(false);
|
||||
expect(mount({ style: { minHeight: '100px' } }, false).hasAttribute('data-wsb-dropzone')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -95,8 +95,11 @@ export const Container: UserComponent<ContainerProps> = ({
|
||||
// follows the current device's Alignment / Vertical alignment.
|
||||
const layout = containerLayout(style, needsBoxedWrapper);
|
||||
|
||||
// 40px min-height = editor-only DROP ZONE, so only an EMPTY container gets it. A container with
|
||||
// content must size like the published page (toHtml adds no min-height).
|
||||
const isEmpty = React.Children.count(children) === 0;
|
||||
const outerStyle: CSSProperties = {
|
||||
minHeight: '40px',
|
||||
...(isEmpty ? { minHeight: '40px' } : {}),
|
||||
...style,
|
||||
...(fullWidth ? { width: '100vw', marginLeft: 'calc(-50vw + 50%)' } : {}),
|
||||
...layout.outer,
|
||||
@@ -114,6 +117,7 @@ export const Container: UserComponent<ContainerProps> = ({
|
||||
style: outerStyle,
|
||||
'data-craft-container': 'true',
|
||||
'data-fullwidth': fullWidth ? '' : undefined,
|
||||
'data-wsb-dropzone': isEmpty && !style.minHeight ? '' : undefined,
|
||||
id: idValue,
|
||||
className: cssClass || undefined,
|
||||
},
|
||||
|
||||
@@ -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