Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0419291259 |
@@ -44,29 +44,3 @@ describe('Icon.toHtml XSS hardening', () => {
|
|||||||
expect(html).not.toMatch(/"\s+onclick="/);
|
expect(html).not.toMatch(/"\s+onclick="/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Icon.toHtml bgShape/bgColor/bgSize rendering (built but, until this panel update, unexposed)', () => {
|
|
||||||
test('bgShape="circle" + bgColor render a colored 50%-radius background box', () => {
|
|
||||||
const { html } = toHtml({ icon: 'fa-star', bgShape: 'circle', bgColor: '#3b82f6', bgSize: '64px' }, '');
|
|
||||||
expect(html).toContain('background-color:#3b82f6');
|
|
||||||
expect(html).toContain('border-radius:50%');
|
|
||||||
expect(html).toContain('width:64px');
|
|
||||||
expect(html).toContain('height:64px');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('bgShape="none" (default) renders the bare icon with no background wrapper', () => {
|
|
||||||
const { html } = toHtml({ icon: 'fa-star' }, '');
|
|
||||||
expect(html).not.toContain('background-color');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Icon.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (Icon as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ interface IconProps {
|
|||||||
bgSize?: string;
|
bgSize?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBgBorderRadius(shape: string): string {
|
function getBgBorderRadius(shape: string): string {
|
||||||
@@ -101,11 +96,6 @@ Icon.craft = {
|
|||||||
bgSize: '56px',
|
bgSize: '56px',
|
||||||
link: '',
|
link: '',
|
||||||
style: {},
|
style: {},
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -51,43 +51,3 @@ describe('SocialLinks.toHtml XSS hardening (iconSize/iconColor/iconBgColor/gap i
|
|||||||
expect(html).not.toContain('javascript:alert(1)');
|
expect(html).not.toContain('javascript:alert(1)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('SocialLinks.toHtml iconShape/gap emission (previously built but unexposed in SocialStylePanel)', () => {
|
|
||||||
test('iconShape="circle" emits a 50% border-radius on the wrapping <a>', () => {
|
|
||||||
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'circle' }, '');
|
|
||||||
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:50%[^"]*"/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('iconShape="square" emits border-radius:0', () => {
|
|
||||||
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'square' }, '');
|
|
||||||
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:0[^"]*"/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('iconShape="rounded" emits a 6px border-radius', () => {
|
|
||||||
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'rounded' }, '');
|
|
||||||
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:6px[^"]*"/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('iconShape="none" omits the background box entirely (transparent bg, no fixed box size)', () => {
|
|
||||||
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'none' }, '');
|
|
||||||
const aTag = html.match(/<a[^>]*>/)![0];
|
|
||||||
expect(aTag).toContain('background-color:transparent');
|
|
||||||
expect(aTag).not.toContain('border-radius');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('gap emits on the wrapper <div> style', () => {
|
|
||||||
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], gap: '24px' }, '');
|
|
||||||
expect(html).toMatch(/<div[^>]*style="[^"]*gap:24px[^"]*"/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SocialLinks.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (SocialLinks as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -17,11 +17,6 @@ interface SocialLinksProps {
|
|||||||
gap?: string;
|
gap?: string;
|
||||||
alignment?: 'left' | 'center' | 'right';
|
alignment?: 'left' | 'center' | 'right';
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformIcons: Record<string, string> = {
|
const platformIcons: Record<string, string> = {
|
||||||
@@ -156,11 +151,6 @@ SocialLinks.craft = {
|
|||||||
gap: '10px',
|
gap: '10px',
|
||||||
alignment: 'center',
|
alignment: 'center',
|
||||||
style: {},
|
style: {},
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -75,14 +75,3 @@ describe('StarRating.toHtml XSS hardening (rating/maxStars into aria-label, F2.2
|
|||||||
expect(html).toMatch(/<span role="img" aria-label="Rating: 4\.5 out of 5"/);
|
expect(html).toMatch(/<span role="img" aria-label="Rating: 4\.5 out of 5"/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('StarRating.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (StarRating as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ interface StarRatingProps {
|
|||||||
filledColor?: string;
|
filledColor?: string;
|
||||||
emptyColor?: string;
|
emptyColor?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StarRating: UserComponent<StarRatingProps> = ({
|
export const StarRating: UserComponent<StarRatingProps> = ({
|
||||||
@@ -92,11 +87,6 @@ StarRating.craft = {
|
|||||||
filledColor: '#f59e0b',
|
filledColor: '#f59e0b',
|
||||||
emptyColor: '#d1d5db',
|
emptyColor: '#d1d5db',
|
||||||
style: {},
|
style: {},
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import { ImageBlock } from './ImageBlock';
|
import { ImageBlock, pxAttr } from './ImageBlock';
|
||||||
|
|
||||||
const toHtml = (ImageBlock as any).toHtml;
|
const toHtml = (ImageBlock as any).toHtml;
|
||||||
|
|
||||||
@@ -32,3 +32,95 @@ describe('ImageBlock.toHtml src/alt XSS hardening', () => {
|
|||||||
expect(html).toContain('alt="A photo"');
|
expect(html).toContain('alt="A photo"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ImageBlock.toHtml perf attributes (always emitted)', () => {
|
||||||
|
test('loading="lazy" and decoding="async" are always present', () => {
|
||||||
|
const { html } = toHtml({ src: 'https://example.com/photo.jpg' }, '');
|
||||||
|
expect(html).toContain('loading="lazy"');
|
||||||
|
expect(html).toContain('decoding="async"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('width/height attributes are emitted when the style has plain px values', () => {
|
||||||
|
const { html } = toHtml({ src: 'https://example.com/photo.jpg', style: { width: '400px', height: '300px' } }, '');
|
||||||
|
expect(html).toContain('width="400"');
|
||||||
|
expect(html).toContain('height="300"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('width/height attributes are omitted when the style value is not a plain px length', () => {
|
||||||
|
const { html } = toHtml({ src: 'https://example.com/photo.jpg', style: { width: '50%', height: 'auto' } }, '');
|
||||||
|
expect(html).not.toMatch(/\swidth="/);
|
||||||
|
expect(html).not.toMatch(/\sheight="/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('pxAttr', () => {
|
||||||
|
test('extracts the numeric portion of a plain px length', () => {
|
||||||
|
expect(pxAttr('400px')).toBe('400');
|
||||||
|
expect(pxAttr('12.5px')).toBe('12.5');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns undefined for non-px units, non-string, or unset values', () => {
|
||||||
|
expect(pxAttr('50%')).toBeUndefined();
|
||||||
|
expect(pxAttr('auto')).toBeUndefined();
|
||||||
|
expect(pxAttr(undefined)).toBeUndefined();
|
||||||
|
expect(pxAttr(400)).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ImageBlock.toHtml CSS framing crop (aspect-ratio + object-fit + object-position)', () => {
|
||||||
|
test('style.aspectRatio, objectFit, objectPosition all flow into the emitted style attribute', () => {
|
||||||
|
const { html } = toHtml(
|
||||||
|
{ src: 'https://example.com/photo.jpg', style: { aspectRatio: '16 / 9', objectFit: 'cover', objectPosition: 'center top' } },
|
||||||
|
''
|
||||||
|
);
|
||||||
|
expect(html).toContain('aspect-ratio:16 / 9');
|
||||||
|
expect(html).toContain('object-fit:cover');
|
||||||
|
expect(html).toContain('object-position:center top');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ImageBlock.toHtml box-model styles (margin/padding/border/shadow/opacity)', () => {
|
||||||
|
test('margin/padding/border/box-shadow/opacity all flow into the emitted style attribute', () => {
|
||||||
|
const { html } = toHtml(
|
||||||
|
{
|
||||||
|
src: 'https://example.com/photo.jpg',
|
||||||
|
style: {
|
||||||
|
marginTop: '10px', marginRight: '10px', marginBottom: '10px', marginLeft: '10px',
|
||||||
|
paddingTop: '5px',
|
||||||
|
border: '2px solid #ff0000',
|
||||||
|
boxShadow: '0 4px 8px rgba(0,0,0,0.12)',
|
||||||
|
opacity: '0.8',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
''
|
||||||
|
);
|
||||||
|
expect(html).toContain('margin-top:10px');
|
||||||
|
expect(html).toContain('padding-top:5px');
|
||||||
|
expect(html).toContain('border:2px solid #ff0000');
|
||||||
|
expect(html).toContain('box-shadow:0 4px 8px rgba(0,0,0,0.12)');
|
||||||
|
expect(html).toContain('opacity:0.8');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ImageBlock.craft.props exposes the box-model/animation/visibility rollout', () => {
|
||||||
|
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
||||||
|
const props = (ImageBlock as any).craft.props;
|
||||||
|
expect(props.animation).toBe('');
|
||||||
|
expect(props.animationDelay).toBe('0');
|
||||||
|
expect(props.hideOnDesktop).toBe(false);
|
||||||
|
expect(props.hideOnTablet).toBe(false);
|
||||||
|
expect(props.hideOnMobile).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('style carries blank/default box-model and crop keys', () => {
|
||||||
|
const style = (ImageBlock as any).craft.props.style;
|
||||||
|
expect(style).toHaveProperty('aspectRatio');
|
||||||
|
expect(style).toHaveProperty('objectFit');
|
||||||
|
expect(style).toHaveProperty('objectPosition');
|
||||||
|
expect(style).toHaveProperty('marginTop');
|
||||||
|
expect(style).toHaveProperty('paddingTop');
|
||||||
|
expect(style.border).toBe('none');
|
||||||
|
expect(style.boxShadow).toBe('none');
|
||||||
|
expect(style.opacity).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -9,6 +9,23 @@ interface ImageBlockProps {
|
|||||||
src?: string;
|
src?: string;
|
||||||
alt?: string;
|
alt?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extracts the numeric portion of a plain "<n>px" CSS length string, for
|
||||||
|
* emitting real `width`/`height` HTML attributes on the exported `<img>`
|
||||||
|
* (helps the browser reserve layout space before the image loads --
|
||||||
|
* avoiding CLS -- something a CSS-only width/height can't do on its own).
|
||||||
|
* Returns undefined for any other unit ('%', 'auto', '', etc.) so the
|
||||||
|
* attribute is simply omitted when the pixel size isn't known. */
|
||||||
|
export function pxAttr(v: unknown): string | undefined {
|
||||||
|
if (typeof v !== 'string') return undefined;
|
||||||
|
const m = v.trim().match(/^(\d+(?:\.\d+)?)px$/);
|
||||||
|
return m ? m[1] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper: upload a file to the WHP API and return the proxy URL
|
// Helper: upload a file to the WHP API and return the proxy URL
|
||||||
@@ -83,7 +100,27 @@ export const ImageBlock: UserComponent<ImageBlockProps> = ({
|
|||||||
|
|
||||||
ImageBlock.craft = {
|
ImageBlock.craft = {
|
||||||
displayName: 'Image',
|
displayName: 'Image',
|
||||||
props: { src: PLACEHOLDER_SRC, alt: '', style: { width: '100%', height: 'auto' } },
|
props: {
|
||||||
|
src: PLACEHOLDER_SRC,
|
||||||
|
alt: '',
|
||||||
|
style: {
|
||||||
|
width: '100%',
|
||||||
|
height: 'auto',
|
||||||
|
aspectRatio: '',
|
||||||
|
objectFit: '' as CSSProperties['objectFit'],
|
||||||
|
objectPosition: '',
|
||||||
|
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
||||||
|
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
||||||
|
border: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
},
|
||||||
rules: { canDrag: () => true, canMoveIn: () => false, canMoveOut: () => true },
|
rules: { canDrag: () => true, canMoveIn: () => false, canMoveOut: () => true },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,5 +132,8 @@ ImageBlock.craft = {
|
|||||||
}
|
}
|
||||||
const s = cssPropsToString({ display: 'block', maxWidth: '100%', ...props.style });
|
const s = cssPropsToString({ display: 'block', maxWidth: '100%', ...props.style });
|
||||||
const alt = props.alt ? ` alt="${escapeAttr(props.alt)}"` : ' alt=""';
|
const alt = props.alt ? ` alt="${escapeAttr(props.alt)}"` : ' alt=""';
|
||||||
return { html: `<img src="${escapeAttr(safeImageUrl(src))}"${alt}${s ? ` style="${s}"` : ''} />` };
|
const widthAttr = pxAttr((props.style as any)?.width);
|
||||||
|
const heightAttr = pxAttr((props.style as any)?.height);
|
||||||
|
const dims = `${widthAttr ? ` width="${widthAttr}"` : ''}${heightAttr ? ` height="${heightAttr}"` : ''}`;
|
||||||
|
return { html: `<img src="${escapeAttr(safeImageUrl(src))}"${alt}${dims} loading="lazy" decoding="async"${s ? ` style="${s}"` : ''} />` };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,6 +28,49 @@ describe('MapEmbed.toHtml iframe src ampersand encoding (F-export review Minor)'
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('MapEmbed.toHtml box-model styles (margin/padding/border/shadow/opacity)', () => {
|
||||||
|
test('margin/padding/border/box-shadow/opacity all flow into the wrapper style attribute', () => {
|
||||||
|
const { html } = toHtml(
|
||||||
|
{
|
||||||
|
address: 'New York, NY',
|
||||||
|
style: {
|
||||||
|
marginTop: '16px',
|
||||||
|
paddingRight: '4px',
|
||||||
|
border: '1px solid #cccccc',
|
||||||
|
boxShadow: '0 4px 8px rgba(0,0,0,0.12)',
|
||||||
|
opacity: '0.95',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
''
|
||||||
|
);
|
||||||
|
expect(html).toContain('margin-top:16px');
|
||||||
|
expect(html).toContain('padding-right:4px');
|
||||||
|
expect(html).toContain('border:1px solid #cccccc');
|
||||||
|
expect(html).toContain('box-shadow:0 4px 8px rgba(0,0,0,0.12)');
|
||||||
|
expect(html).toContain('opacity:0.95');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('MapEmbed.craft.props exposes the animation/visibility rollout', () => {
|
||||||
|
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
||||||
|
const props = (MapEmbed as any).craft.props;
|
||||||
|
expect(props.animation).toBe('');
|
||||||
|
expect(props.animationDelay).toBe('0');
|
||||||
|
expect(props.hideOnDesktop).toBe(false);
|
||||||
|
expect(props.hideOnTablet).toBe(false);
|
||||||
|
expect(props.hideOnMobile).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('style carries blank/default box-model keys', () => {
|
||||||
|
const style = (MapEmbed as any).craft.props.style;
|
||||||
|
expect(style).toHaveProperty('marginTop');
|
||||||
|
expect(style).toHaveProperty('paddingTop');
|
||||||
|
expect(style.border).toBe('none');
|
||||||
|
expect(style.boxShadow).toBe('none');
|
||||||
|
expect(style.opacity).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('MapEmbed.toHtml address/zoom/height XSS hardening', () => {
|
describe('MapEmbed.toHtml address/zoom/height XSS hardening', () => {
|
||||||
test('a malicious address cannot break out of the src or title attribute', () => {
|
test('a malicious address cannot break out of the src or title attribute', () => {
|
||||||
const malicious = 'X" onerror="alert(1)';
|
const malicious = 'X" onerror="alert(1)';
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ interface MapEmbedProps {
|
|||||||
zoom?: number;
|
zoom?: number;
|
||||||
height?: string;
|
height?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMapUrl(address: string, zoom: number): string {
|
function buildMapUrl(address: string, zoom: number): string {
|
||||||
@@ -70,7 +75,18 @@ MapEmbed.craft = {
|
|||||||
address: 'New York, NY',
|
address: 'New York, NY',
|
||||||
zoom: 14,
|
zoom: 14,
|
||||||
height: '400px',
|
height: '400px',
|
||||||
style: {},
|
style: {
|
||||||
|
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
||||||
|
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
||||||
|
border: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -118,3 +118,75 @@ describe('VideoBlock.toHtml iframe src ampersand encoding (F-export review Minor
|
|||||||
expect(srcMatch![1]).not.toMatch(/&(?!amp;)/);
|
expect(srcMatch![1]).not.toMatch(/&(?!amp;)/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('VideoBlock.toHtml size + aspect ratio (frame honors style props, not a hardcoded 16:9)', () => {
|
||||||
|
test('direct file: style.width flows to the wrapper, style.aspectRatio flows to the <video>', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4', style: { width: '50%', aspectRatio: '4 / 3' } }, '');
|
||||||
|
expect(html).toMatch(/<div style="[^"]*width:50%[^"]*"/);
|
||||||
|
expect(html).toMatch(/<video[^>]*style="[^"]*aspect-ratio:4 \/ 3[^"]*"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('direct file: no aspectRatio set -- no aspect-ratio declaration is forced onto the <video>', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4' }, '');
|
||||||
|
const videoTag = html.match(/<video[^>]*>/)![0];
|
||||||
|
expect(videoTag).not.toContain('aspect-ratio');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('YouTube/Vimeo: style.aspectRatio overrides the 16:9 default on the iframe container', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://vimeo.com/123456789', style: { aspectRatio: '1 / 1' } }, '');
|
||||||
|
expect(html).toMatch(/<div[^>]*style="[^"]*aspect-ratio:1 \/ 1[^"]*"[^>]*><iframe/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('YouTube/Vimeo: defaults to 16 / 9 when no aspectRatio style is set', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://vimeo.com/123456789' }, '');
|
||||||
|
expect(html).toMatch(/<div[^>]*style="[^"]*aspect-ratio:16 \/ 9[^"]*"[^>]*><iframe/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('VideoBlock.toHtml poster + preload (file type)', () => {
|
||||||
|
test('poster attribute is emitted (escaped) and preload="metadata" is always present on a direct file', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4', poster: 'https://example.com/poster.jpg' }, '');
|
||||||
|
expect(html).toContain('poster="https://example.com/poster.jpg"');
|
||||||
|
expect(html).toContain('preload="metadata"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('no poster prop -- no poster attribute is emitted, but preload="metadata" still is', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4' }, '');
|
||||||
|
expect(html).not.toContain('poster=');
|
||||||
|
expect(html).toContain('preload="metadata"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a malicious poster (javascript: scheme) is blocked by safeImageUrl', () => {
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4', poster: 'javascript:alert(1)' }, '');
|
||||||
|
expect(html).not.toContain('javascript:');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a poster value cannot break out of the poster attribute', () => {
|
||||||
|
const malicious = 'https://example.com/x.jpg" onerror="alert(1)';
|
||||||
|
const { html } = toHtml({ videoUrl: 'https://example.com/clip.mp4', poster: malicious }, '');
|
||||||
|
expect(html).not.toContain('onerror="alert(1)"');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('VideoBlock.craft.props exposes the box-model/animation/visibility rollout', () => {
|
||||||
|
test('poster, animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
||||||
|
const props = (VideoBlock as any).craft.props;
|
||||||
|
expect(props.poster).toBe('');
|
||||||
|
expect(props.animation).toBe('');
|
||||||
|
expect(props.animationDelay).toBe('0');
|
||||||
|
expect(props.hideOnDesktop).toBe(false);
|
||||||
|
expect(props.hideOnTablet).toBe(false);
|
||||||
|
expect(props.hideOnMobile).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('style carries blank/default box-model + size/aspect keys', () => {
|
||||||
|
const style = (VideoBlock as any).craft.props.style;
|
||||||
|
expect(style).toHaveProperty('width');
|
||||||
|
expect(style).toHaveProperty('aspectRatio');
|
||||||
|
expect(style).toHaveProperty('marginTop');
|
||||||
|
expect(style).toHaveProperty('paddingTop');
|
||||||
|
expect(style.border).toBe('none');
|
||||||
|
expect(style.boxShadow).toBe('none');
|
||||||
|
expect(style.opacity).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { CSSProperties } from 'react';
|
|||||||
import { useNode, Element, UserComponent } from '@craftjs/core';
|
import { useNode, Element, UserComponent } from '@craftjs/core';
|
||||||
import { Container } from '../layout/Container';
|
import { Container } from '../layout/Container';
|
||||||
import { cssPropsToString } from '../../utils/style-helpers';
|
import { cssPropsToString } from '../../utils/style-helpers';
|
||||||
import { escapeAttr, safeUrl } from '../../utils/escape';
|
import { escapeAttr, safeUrl, safeImageUrl } from '../../utils/escape';
|
||||||
|
|
||||||
/* ---------- Types ---------- */
|
/* ---------- Types ---------- */
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ interface VideoBlockProps {
|
|||||||
videoUrl?: string;
|
videoUrl?: string;
|
||||||
videoType?: VideoType;
|
videoType?: VideoType;
|
||||||
embedUrl?: string;
|
embedUrl?: string;
|
||||||
|
poster?: string;
|
||||||
autoplay?: boolean;
|
autoplay?: boolean;
|
||||||
muted?: boolean;
|
muted?: boolean;
|
||||||
loop?: boolean;
|
loop?: boolean;
|
||||||
@@ -22,6 +23,11 @@ interface VideoBlockProps {
|
|||||||
innerMaxWidth?: string;
|
innerMaxWidth?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- URL detection ---------- */
|
/* ---------- URL detection ---------- */
|
||||||
@@ -120,6 +126,7 @@ export const VideoBlock: UserComponent<VideoBlockProps> = ({
|
|||||||
videoUrl = '',
|
videoUrl = '',
|
||||||
videoType: _videoTypeProp,
|
videoType: _videoTypeProp,
|
||||||
embedUrl: _embedUrlProp,
|
embedUrl: _embedUrlProp,
|
||||||
|
poster = '',
|
||||||
autoplay = false,
|
autoplay = false,
|
||||||
muted = true,
|
muted = true,
|
||||||
loop = false,
|
loop = false,
|
||||||
@@ -259,8 +266,7 @@ export const VideoBlock: UserComponent<VideoBlockProps> = ({
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
paddingBottom: '56.25%',
|
aspectRatio: (style as any)?.aspectRatio || '16 / 9',
|
||||||
height: 0,
|
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
borderRadius: (style as any)?.borderRadius || undefined,
|
borderRadius: (style as any)?.borderRadius || undefined,
|
||||||
}}
|
}}
|
||||||
@@ -269,8 +275,7 @@ export const VideoBlock: UserComponent<VideoBlockProps> = ({
|
|||||||
src={buildEmbedParams(embedUrl, { autoplay, muted, loop, controls })}
|
src={buildEmbedParams(embedUrl, { autoplay, muted, loop, controls })}
|
||||||
style={{
|
style={{
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: 0,
|
inset: 0,
|
||||||
left: 0,
|
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
@@ -284,14 +289,18 @@ export const VideoBlock: UserComponent<VideoBlockProps> = ({
|
|||||||
{type === 'file' && (
|
{type === 'file' && (
|
||||||
<video
|
<video
|
||||||
src={embedUrl}
|
src={embedUrl}
|
||||||
|
poster={poster || undefined}
|
||||||
autoPlay={autoplay}
|
autoPlay={autoplay}
|
||||||
muted={muted}
|
muted={muted}
|
||||||
loop={loop}
|
loop={loop}
|
||||||
controls={controls}
|
controls={controls}
|
||||||
|
preload="metadata"
|
||||||
playsInline
|
playsInline
|
||||||
style={{
|
style={{
|
||||||
display: 'block',
|
display: 'block',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
aspectRatio: (style as any)?.aspectRatio || undefined,
|
||||||
|
objectFit: 'cover',
|
||||||
borderRadius: (style as any)?.borderRadius || undefined,
|
borderRadius: (style as any)?.borderRadius || undefined,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -310,6 +319,7 @@ VideoBlock.craft = {
|
|||||||
videoUrl: '',
|
videoUrl: '',
|
||||||
videoType: 'none',
|
videoType: 'none',
|
||||||
embedUrl: '',
|
embedUrl: '',
|
||||||
|
poster: '',
|
||||||
autoplay: false,
|
autoplay: false,
|
||||||
muted: true,
|
muted: true,
|
||||||
loop: false,
|
loop: false,
|
||||||
@@ -318,7 +328,20 @@ VideoBlock.craft = {
|
|||||||
overlayColor: '#000000',
|
overlayColor: '#000000',
|
||||||
overlayOpacity: 50,
|
overlayOpacity: 50,
|
||||||
innerMaxWidth: '1200px',
|
innerMaxWidth: '1200px',
|
||||||
style: {},
|
style: {
|
||||||
|
width: '',
|
||||||
|
aspectRatio: '',
|
||||||
|
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
||||||
|
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
||||||
|
border: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -334,6 +357,7 @@ VideoBlock.craft = {
|
|||||||
(VideoBlock as any).toHtml = (props: VideoBlockProps, childrenHtml: string) => {
|
(VideoBlock as any).toHtml = (props: VideoBlockProps, childrenHtml: string) => {
|
||||||
const {
|
const {
|
||||||
videoUrl = '',
|
videoUrl = '',
|
||||||
|
poster = '',
|
||||||
autoplay = false,
|
autoplay = false,
|
||||||
muted = true,
|
muted = true,
|
||||||
loop: doLoop = false,
|
loop: doLoop = false,
|
||||||
@@ -422,15 +446,13 @@ VideoBlock.craft = {
|
|||||||
const iframeSrc = buildEmbedParams(embedUrl, { autoplay, muted, loop: doLoop, controls });
|
const iframeSrc = buildEmbedParams(embedUrl, { autoplay, muted, loop: doLoop, controls });
|
||||||
const containerStyle = cssPropsToString({
|
const containerStyle = cssPropsToString({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
paddingBottom: '56.25%',
|
aspectRatio: (style as any)?.aspectRatio || '16 / 9',
|
||||||
height: '0',
|
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
borderRadius: (style as any)?.borderRadius || undefined,
|
borderRadius: (style as any)?.borderRadius || undefined,
|
||||||
});
|
});
|
||||||
const iframeStyle = cssPropsToString({
|
const iframeStyle = cssPropsToString({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '0',
|
inset: '0',
|
||||||
left: '0',
|
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
@@ -447,13 +469,16 @@ VideoBlock.craft = {
|
|||||||
if (doLoop) vidAttrs.push('loop');
|
if (doLoop) vidAttrs.push('loop');
|
||||||
if (controls) vidAttrs.push('controls');
|
if (controls) vidAttrs.push('controls');
|
||||||
vidAttrs.push('playsinline');
|
vidAttrs.push('playsinline');
|
||||||
|
const posterAttr = poster ? ` poster="${escapeAttr(safeImageUrl(poster))}"` : '';
|
||||||
const vidStyle = cssPropsToString({
|
const vidStyle = cssPropsToString({
|
||||||
display: 'block',
|
display: 'block',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
aspectRatio: (style as any)?.aspectRatio || undefined,
|
||||||
|
objectFit: 'cover',
|
||||||
borderRadius: (style as any)?.borderRadius || undefined,
|
borderRadius: (style as any)?.borderRadius || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: `<div${wrapperStyle ? ` style="${wrapperStyle}"` : ''}><video src="${escapeAttr(safeUrl(embedUrl))}" ${vidAttrs.join(' ')}${vidStyle ? ` style="${vidStyle}"` : ''}></video></div>`,
|
html: `<div${wrapperStyle ? ` style="${wrapperStyle}"` : ''}><video src="${escapeAttr(safeUrl(embedUrl))}"${posterAttr} preload="metadata" ${vidAttrs.join(' ')}${vidStyle ? ` style="${vidStyle}"` : ''}></video></div>`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
import { Accordion } from './Accordion';
|
|
||||||
|
|
||||||
const toHtml = (Accordion as any).toHtml;
|
|
||||||
|
|
||||||
const items = [
|
|
||||||
{ title: 'Q1', content: 'A1', isOpen: true },
|
|
||||||
{ title: 'Q2', content: 'A2', isOpen: false },
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('Accordion.toHtml basic export', () => {
|
|
||||||
test('renders a <details> per item with the open attribute honored', () => {
|
|
||||||
const { html } = toHtml({ items }, '');
|
|
||||||
const detailsBlocks = html.match(/<details[^>]*>/g) || [];
|
|
||||||
expect(detailsBlocks.length).toBe(2);
|
|
||||||
expect(detailsBlocks[0]).toContain(' open');
|
|
||||||
expect(detailsBlocks[1]).not.toContain(' open');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('headerBg/headerColor/contentBg/borderColor emit into the panel styles', () => {
|
|
||||||
const { html } = toHtml({ items, headerBg: '#111111', headerColor: '#222222', contentBg: '#333333', borderColor: '#444444' }, '');
|
|
||||||
expect(html).toContain('#111111');
|
|
||||||
expect(html).toContain('#222222');
|
|
||||||
expect(html).toContain('#333333');
|
|
||||||
expect(html).toContain('#444444');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Accordion.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (Accordion as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -17,11 +17,6 @@ interface AccordionProps {
|
|||||||
contentBg?: string;
|
contentBg?: string;
|
||||||
borderColor?: string;
|
borderColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultItems: AccordionItem[] = [
|
const defaultItems: AccordionItem[] = [
|
||||||
@@ -140,11 +135,6 @@ Accordion.craft = {
|
|||||||
contentBg: '#ffffff',
|
contentBg: '#ffffff',
|
||||||
borderColor: '#e2e8f0',
|
borderColor: '#e2e8f0',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
import { CTASection } from './CTASection';
|
|
||||||
|
|
||||||
const toHtml = (CTASection as any).toHtml;
|
|
||||||
|
|
||||||
describe('CTASection.toHtml basic export', () => {
|
|
||||||
test('renders heading, description, and CTA buttons', () => {
|
|
||||||
const { html } = toHtml({ heading: 'Hi', description: 'Sub', ctas: [{ text: 'Go', href: '#', variant: 'primary' }] }, '');
|
|
||||||
expect(html).toContain('Hi');
|
|
||||||
expect(html).toContain('Sub');
|
|
||||||
expect(html).toContain('Go');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('box-model style props (margin/padding/border/boxShadow/opacity) flow through to the section style=""', () => {
|
|
||||||
const { html } = toHtml({
|
|
||||||
heading: 'Hi',
|
|
||||||
description: 'Sub',
|
|
||||||
style: { marginTop: '10px', paddingLeft: '5px', border: '1px solid #000', boxShadow: '0 1px 2px rgba(0,0,0,0.1)', opacity: '0.5' },
|
|
||||||
}, '');
|
|
||||||
expect(html).toContain('margin-top:10px');
|
|
||||||
expect(html).toContain('padding-left:5px');
|
|
||||||
expect(html).toContain('border:1px solid #000');
|
|
||||||
expect(html).toContain('box-shadow:0 1px 2px rgba(0,0,0,0.1)');
|
|
||||||
expect(html).toContain('opacity:0.5');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('CTASection.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (CTASection as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -14,11 +14,6 @@ interface CTASectionProps {
|
|||||||
gradient?: string;
|
gradient?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||||
@@ -88,11 +83,6 @@ CTASection.craft = {
|
|||||||
gradient: defaultGradient,
|
gradient: defaultGradient,
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
style: {},
|
style: {},
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
import { CallToAction } from './CallToAction';
|
|
||||||
|
|
||||||
const toHtml = (CallToAction as any).toHtml;
|
|
||||||
|
|
||||||
describe('CallToAction.toHtml basic export', () => {
|
|
||||||
test('renders heading, description, and CTA buttons', () => {
|
|
||||||
const { html } = toHtml({ heading: 'Hi', description: 'Sub', ctas: [{ text: 'Go', href: '#', variant: 'primary' }] }, '');
|
|
||||||
expect(html).toContain('Hi');
|
|
||||||
expect(html).toContain('Sub');
|
|
||||||
expect(html).toContain('Go');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('box-model style props (margin/padding/border/boxShadow/opacity) flow through to the section style=""', () => {
|
|
||||||
const { html } = toHtml({
|
|
||||||
heading: 'Hi',
|
|
||||||
description: 'Sub',
|
|
||||||
style: { marginBottom: '12px', paddingRight: '6px', border: '2px dashed #333', boxShadow: '0 4px 8px rgba(0,0,0,0.12)', opacity: '0.75' },
|
|
||||||
}, '');
|
|
||||||
expect(html).toContain('margin-bottom:12px');
|
|
||||||
expect(html).toContain('padding-right:6px');
|
|
||||||
expect(html).toContain('border:2px dashed #333');
|
|
||||||
expect(html).toContain('box-shadow:0 4px 8px rgba(0,0,0,0.12)');
|
|
||||||
expect(html).toContain('opacity:0.75');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('CallToAction.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (CallToAction as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -21,11 +21,6 @@ interface CallToActionProps {
|
|||||||
buttonColor?: string;
|
buttonColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||||
@@ -136,11 +131,6 @@ CallToAction.craft = {
|
|||||||
textColor: '#ffffff',
|
textColor: '#ffffff',
|
||||||
buttonColor: '#ffffff',
|
buttonColor: '#ffffff',
|
||||||
style: {},
|
style: {},
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -139,3 +139,46 @@ describe('ContentSlider.toHtml interval is NOT runtime-type-checked -- must be c
|
|||||||
expect(html).toMatch(/setInterval\(function\(\)\{show\(current\+1\);\},3000\);/);
|
expect(html).toMatch(/setInterval\(function\(\)\{show\(current\+1\);\},3000\);/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ContentSlider.toHtml box-model styles (margin/padding/border/shadow/opacity)', () => {
|
||||||
|
test('margin/padding/border/box-shadow/opacity all flow into the section style attribute', () => {
|
||||||
|
const { html } = toHtml(
|
||||||
|
{
|
||||||
|
slides,
|
||||||
|
style: {
|
||||||
|
marginBottom: '24px',
|
||||||
|
paddingTop: '8px',
|
||||||
|
border: '3px dashed #00ff00',
|
||||||
|
boxShadow: '0 10px 24px rgba(0,0,0,0.18)',
|
||||||
|
opacity: '0.75',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
''
|
||||||
|
);
|
||||||
|
expect(html).toContain('margin-bottom:24px');
|
||||||
|
expect(html).toContain('padding-top:8px');
|
||||||
|
expect(html).toContain('border:3px dashed #00ff00');
|
||||||
|
expect(html).toContain('box-shadow:0 10px 24px rgba(0,0,0,0.18)');
|
||||||
|
expect(html).toContain('opacity:0.75');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ContentSlider.craft.props exposes the animation/visibility rollout', () => {
|
||||||
|
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
||||||
|
const props = (ContentSlider as any).craft.props;
|
||||||
|
expect(props.animation).toBe('');
|
||||||
|
expect(props.animationDelay).toBe('0');
|
||||||
|
expect(props.hideOnDesktop).toBe(false);
|
||||||
|
expect(props.hideOnTablet).toBe(false);
|
||||||
|
expect(props.hideOnMobile).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('style carries blank/default box-model keys', () => {
|
||||||
|
const style = (ContentSlider as any).craft.props.style;
|
||||||
|
expect(style).toHaveProperty('marginTop');
|
||||||
|
expect(style).toHaveProperty('paddingTop');
|
||||||
|
expect(style.border).toBe('none');
|
||||||
|
expect(style.boxShadow).toBe('none');
|
||||||
|
expect(style.opacity).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ interface ContentSliderProps {
|
|||||||
showArrows?: boolean;
|
showArrows?: boolean;
|
||||||
height?: string;
|
height?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSlides: Slide[] = [
|
const defaultSlides: Slide[] = [
|
||||||
@@ -227,7 +232,18 @@ ContentSlider.craft = {
|
|||||||
showDots: true,
|
showDots: true,
|
||||||
showArrows: true,
|
showArrows: true,
|
||||||
height: '400px',
|
height: '400px',
|
||||||
style: {},
|
style: {
|
||||||
|
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
||||||
|
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
||||||
|
border: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -62,14 +62,3 @@ describe('Countdown.toHtml script nit: ticking interval stops at zero', () => {
|
|||||||
expect(html).toMatch(/if\s*\(\s*target\s*-\s*Date\.now\(\)\s*>\s*0\s*\)\s*\{/);
|
expect(html).toMatch(/if\s*\(\s*target\s*-\s*Date\.now\(\)\s*>\s*0\s*\)\s*\{/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Countdown.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (Countdown as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ interface CountdownProps {
|
|||||||
labelColor?: string;
|
labelColor?: string;
|
||||||
bgColor?: string;
|
bgColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TimeLeft {
|
interface TimeLeft {
|
||||||
@@ -144,11 +139,6 @@ Countdown.craft = {
|
|||||||
labelColor: 'rgba(255,255,255,0.7)',
|
labelColor: 'rgba(255,255,255,0.7)',
|
||||||
bgColor: '#18181b',
|
bgColor: '#18181b',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -21,14 +21,3 @@ describe('FeaturesGrid.toHtml image sink uses safeImageUrl (data:image/svg+xml a
|
|||||||
expect(html).toMatch(/<a href=""/);
|
expect(html).toMatch(/<a href=""/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('FeaturesGrid.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (FeaturesGrid as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -17,11 +17,6 @@ interface FeaturesGridProps {
|
|||||||
features?: FeatureItem[];
|
features?: FeatureItem[];
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys image/imageAlt/buttonText/buttonUrl are present (blank) on the defaults so
|
// Keys image/imageAlt/buttonText/buttonUrl are present (blank) on the defaults so
|
||||||
@@ -103,11 +98,6 @@ FeaturesGrid.craft = {
|
|||||||
features: defaultFeatures,
|
features: defaultFeatures,
|
||||||
style: { backgroundColor: '#ffffff' },
|
style: { backgroundColor: '#ffffff' },
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -3,6 +3,73 @@ import { Gallery } from './Gallery';
|
|||||||
|
|
||||||
const toHtml = (Gallery as any).toHtml;
|
const toHtml = (Gallery as any).toHtml;
|
||||||
|
|
||||||
|
describe('Gallery.toHtml columns + lightbox controls (previously unexposed props)', () => {
|
||||||
|
test('columns drives the grid-template-columns repeat count', () => {
|
||||||
|
const { html } = toHtml({ images: [{ src: '/a.jpg', alt: 'a' }], columns: 5 }, '');
|
||||||
|
expect(html).toContain('grid-template-columns:repeat(5,1fr)');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('lightbox=true adds the delegated-listener overlay markup (columns unaffected)', () => {
|
||||||
|
const { html } = toHtml({ images: [{ src: '/a.jpg', alt: 'a' }], columns: 4, lightbox: true }, '');
|
||||||
|
expect(html).toContain('grid-template-columns:repeat(4,1fr)');
|
||||||
|
expect(html).toContain('role="dialog"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a non-numeric columns value falls back safely (Number() coercion, not NaN in the template)', () => {
|
||||||
|
const { html } = toHtml({ images: [{ src: '/a.jpg' }], columns: 'not-a-number' as any }, '');
|
||||||
|
expect(html).toContain('grid-template-columns:repeat(3,1fr)');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Gallery.toHtml box-model styles (margin/padding/border/shadow/opacity)', () => {
|
||||||
|
test('margin/padding/border/box-shadow/opacity all flow into the section style attribute', () => {
|
||||||
|
const { html } = toHtml(
|
||||||
|
{
|
||||||
|
images: [{ src: '/a.jpg', alt: 'a' }],
|
||||||
|
style: {
|
||||||
|
marginTop: '20px',
|
||||||
|
paddingLeft: '12px',
|
||||||
|
border: '1px solid #333333',
|
||||||
|
boxShadow: '0 1px 2px rgba(0,0,0,0.08)',
|
||||||
|
opacity: '0.9',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
''
|
||||||
|
);
|
||||||
|
expect(html).toContain('margin-top:20px');
|
||||||
|
expect(html).toContain('padding-left:12px');
|
||||||
|
expect(html).toContain('border:1px solid #333333');
|
||||||
|
expect(html).toContain('box-shadow:0 1px 2px rgba(0,0,0,0.08)');
|
||||||
|
expect(html).toContain('opacity:0.9');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Gallery.craft.props exposes columns/lightbox + the animation/visibility rollout', () => {
|
||||||
|
test('columns and lightbox have their existing defaults', () => {
|
||||||
|
const props = (Gallery as any).craft.props;
|
||||||
|
expect(props.columns).toBe(3);
|
||||||
|
expect(props.lightbox).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
||||||
|
const props = (Gallery as any).craft.props;
|
||||||
|
expect(props.animation).toBe('');
|
||||||
|
expect(props.animationDelay).toBe('0');
|
||||||
|
expect(props.hideOnDesktop).toBe(false);
|
||||||
|
expect(props.hideOnTablet).toBe(false);
|
||||||
|
expect(props.hideOnMobile).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('style carries blank/default box-model keys', () => {
|
||||||
|
const style = (Gallery as any).craft.props.style;
|
||||||
|
expect(style).toHaveProperty('marginTop');
|
||||||
|
expect(style).toHaveProperty('paddingTop');
|
||||||
|
expect(style.border).toBe('none');
|
||||||
|
expect(style.boxShadow).toBe('none');
|
||||||
|
expect(style.opacity).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Gallery.toHtml lightbox uses a delegated listener, not per-item onclick (A4.3)', () => {
|
describe('Gallery.toHtml lightbox uses a delegated listener, not per-item onclick (A4.3)', () => {
|
||||||
test('no per-item inline onclick with interpolated src', () => {
|
test('no per-item inline onclick with interpolated src', () => {
|
||||||
const { html } = toHtml({ images: [{ src: '/a.jpg', alt: 'a' }], lightbox: true }, '');
|
const { html } = toHtml({ images: [{ src: '/a.jpg', alt: 'a' }], lightbox: true }, '');
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ interface GalleryProps {
|
|||||||
gap?: string;
|
gap?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
lightbox?: boolean;
|
lightbox?: boolean;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const placeholderSvg = (index: number) => {
|
const placeholderSvg = (index: number) => {
|
||||||
@@ -112,8 +117,20 @@ Gallery.craft = {
|
|||||||
images: defaultImages,
|
images: defaultImages,
|
||||||
columns: 3,
|
columns: 3,
|
||||||
gap: '16px',
|
gap: '16px',
|
||||||
style: { backgroundColor: '#ffffff' },
|
style: {
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
|
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
||||||
|
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
||||||
|
border: 'none',
|
||||||
|
boxShadow: 'none',
|
||||||
|
opacity: '1',
|
||||||
|
},
|
||||||
lightbox: false,
|
lightbox: false,
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -73,14 +73,3 @@ describe('NumberCounter.toHtml counter.number is NOT runtime-type-checked -- mus
|
|||||||
expect(html).toContain('data-target="150"');
|
expect(html).toContain('data-target="150"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('NumberCounter.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (NumberCounter as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -16,11 +16,6 @@ interface NumberCounterProps {
|
|||||||
labelColor?: string;
|
labelColor?: string;
|
||||||
numberSize?: string;
|
numberSize?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCounters: Counter[] = [
|
const defaultCounters: Counter[] = [
|
||||||
@@ -104,11 +99,6 @@ NumberCounter.craft = {
|
|||||||
labelColor: '#6b7280',
|
labelColor: '#6b7280',
|
||||||
numberSize: '48px',
|
numberSize: '48px',
|
||||||
style: { backgroundColor: '#ffffff' },
|
style: { backgroundColor: '#ffffff' },
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
|
||||||
import { PricingTable } from './PricingTable';
|
|
||||||
|
|
||||||
const toHtml = (PricingTable as any).toHtml;
|
|
||||||
|
|
||||||
const plans = [
|
|
||||||
{ name: 'Basic', price: '$9', period: '/month', features: ['Feature A'], buttonText: 'Buy', buttonHref: '#', isFeatured: false },
|
|
||||||
{ name: 'Pro', price: '$29', period: '/month', features: ['Feature B'], buttonText: 'Buy', buttonHref: '#', isFeatured: true },
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('PricingTable.toHtml regular-card color overrides (previously hard-coded, now real props)', () => {
|
|
||||||
test('cardBg emits as the non-featured card background', () => {
|
|
||||||
const { html } = toHtml({ plans, cardBg: '#f0f0f0' }, '');
|
|
||||||
expect(html).toContain('background-color:#f0f0f0');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('textColor emits as the non-featured heading/price color', () => {
|
|
||||||
const { html } = toHtml({ plans, textColor: '#123456' }, '');
|
|
||||||
expect(html).toContain('color:#123456');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('subColor emits as the non-featured period text color', () => {
|
|
||||||
const { html } = toHtml({ plans, subColor: '#abcdef' }, '');
|
|
||||||
expect(html).toContain('color:#abcdef');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('featColor emits as the non-featured feature list text color', () => {
|
|
||||||
const { html } = toHtml({ plans, featColor: '#334455' }, '');
|
|
||||||
expect(html).toContain('color:#334455');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checkColor emits as the non-featured bullet color', () => {
|
|
||||||
const { html } = toHtml({ plans, checkColor: '#00ff00' }, '');
|
|
||||||
expect(html).toContain('color:#00ff00');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('btnBg/btnColor emit as the non-featured button colors', () => {
|
|
||||||
const { html } = toHtml({ plans, btnBg: '#111111', btnColor: '#eeeeee' }, '');
|
|
||||||
expect(html).toContain('background-color:#111111');
|
|
||||||
expect(html).toContain('color:#eeeeee');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('unset overrides fall back to the exact prior literals (backward compatible)', () => {
|
|
||||||
const { html } = toHtml({ plans }, '');
|
|
||||||
// Regular (non-featured) card literals unchanged from before these props existed.
|
|
||||||
expect(html).toContain('background-color:#ffffff');
|
|
||||||
expect(html).toContain('color:#18181b');
|
|
||||||
expect(html).toContain('color:#64748b');
|
|
||||||
expect(html).toContain('color:#4b5563');
|
|
||||||
expect(html).toContain('color:#10b981');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('unset btnBg falls back to featuredBg (original derivation)', () => {
|
|
||||||
const { html } = toHtml({ plans, featuredBg: '#654321' }, '');
|
|
||||||
expect(html).toContain('background-color:#654321');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('PricingTable.toHtml XSS hardening (new card color props into style=)', () => {
|
|
||||||
test('a cardBg breakout string cannot escape style=""', () => {
|
|
||||||
const malicious = '#fff" onmouseover="alert(1)';
|
|
||||||
const { html } = toHtml({ plans, cardBg: malicious }, '');
|
|
||||||
expect(html).not.toMatch(/"\s+onmouseover="/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('a textColor breakout string cannot escape style=""', () => {
|
|
||||||
const malicious = '#000" onmouseover="alert(1)';
|
|
||||||
const { html } = toHtml({ plans, textColor: malicious }, '');
|
|
||||||
expect(html).not.toMatch(/"\s+onmouseover="/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('a btnBg breakout string cannot escape style=""', () => {
|
|
||||||
const malicious = '#000" onmouseover="alert(1)';
|
|
||||||
const { html } = toHtml({ plans, btnBg: malicious }, '');
|
|
||||||
expect(html).not.toMatch(/"\s+onmouseover="/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('a btnColor breakout string cannot escape style=""', () => {
|
|
||||||
const malicious = '#000" onmouseover="alert(1)';
|
|
||||||
const { html } = toHtml({ plans, btnColor: malicious }, '');
|
|
||||||
expect(html).not.toMatch(/"\s+onmouseover="/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('PricingTable.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('the new regular-card color props are declared blank by default', () => {
|
|
||||||
const props = (PricingTable as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('cardBg', '');
|
|
||||||
expect(props).toHaveProperty('textColor', '');
|
|
||||||
expect(props).toHaveProperty('subColor', '');
|
|
||||||
expect(props).toHaveProperty('featColor', '');
|
|
||||||
expect(props).toHaveProperty('checkColor', '');
|
|
||||||
expect(props).toHaveProperty('btnBg', '');
|
|
||||||
expect(props).toHaveProperty('btnColor', '');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (PricingTable as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -19,23 +19,6 @@ interface PricingTableProps {
|
|||||||
featuredBg?: string;
|
featuredBg?: string;
|
||||||
bulletType?: string;
|
bulletType?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
/* ---- Regular (non-featured) card colors ----
|
|
||||||
All optional; each falls back to the exact literal the card was
|
|
||||||
previously hard-coded to (or, for the button, to featuredBg -- the
|
|
||||||
button's original derivation) when left unset, so existing saved
|
|
||||||
projects render pixel-identical until a color is explicitly picked. */
|
|
||||||
cardBg?: string;
|
|
||||||
textColor?: string;
|
|
||||||
subColor?: string;
|
|
||||||
featColor?: string;
|
|
||||||
checkColor?: string;
|
|
||||||
btnBg?: string;
|
|
||||||
btnColor?: string;
|
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bulletChars: Record<string, string> = {
|
const bulletChars: Record<string, string> = {
|
||||||
@@ -78,13 +61,6 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
featuredBg = '#3b82f6',
|
featuredBg = '#3b82f6',
|
||||||
bulletType = 'check',
|
bulletType = 'check',
|
||||||
anchorId,
|
anchorId,
|
||||||
cardBg,
|
|
||||||
textColor,
|
|
||||||
subColor,
|
|
||||||
featColor,
|
|
||||||
checkColor,
|
|
||||||
btnBg,
|
|
||||||
btnColor,
|
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
connectors: { connect, drag },
|
connectors: { connect, drag },
|
||||||
@@ -93,14 +69,6 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
selected: node.events.selected,
|
selected: node.events.selected,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const regCardBg = cardBg || '#ffffff';
|
|
||||||
const regTextColor = textColor || '#18181b';
|
|
||||||
const regSubColor = subColor || '#64748b';
|
|
||||||
const regFeatColor = featColor || '#4b5563';
|
|
||||||
const regCheckColor = checkColor || '#10b981';
|
|
||||||
const regBtnBg = btnBg || featuredBg;
|
|
||||||
const regBtnColor = btnColor || '#ffffff';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||||
@@ -127,7 +95,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
style={{
|
style={{
|
||||||
flex: '1 1 280px',
|
flex: '1 1 280px',
|
||||||
maxWidth: '360px',
|
maxWidth: '360px',
|
||||||
backgroundColor: plan.isFeatured ? featuredBg : regCardBg,
|
backgroundColor: plan.isFeatured ? featuredBg : '#ffffff',
|
||||||
border: plan.isFeatured ? 'none' : '1px solid #e2e8f0',
|
border: plan.isFeatured ? 'none' : '1px solid #e2e8f0',
|
||||||
borderRadius: '16px',
|
borderRadius: '16px',
|
||||||
padding: '40px 32px',
|
padding: '40px 32px',
|
||||||
@@ -159,7 +127,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
<h3 style={{
|
<h3 style={{
|
||||||
fontSize: '20px',
|
fontSize: '20px',
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
||||||
marginBottom: '8px',
|
marginBottom: '8px',
|
||||||
marginTop: plan.isFeatured ? '8px' : '0',
|
marginTop: plan.isFeatured ? '8px' : '0',
|
||||||
}}>
|
}}>
|
||||||
@@ -169,14 +137,14 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
<span style={{
|
<span style={{
|
||||||
fontSize: '48px',
|
fontSize: '48px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
||||||
lineHeight: '1',
|
lineHeight: '1',
|
||||||
}}>
|
}}>
|
||||||
{plan.price}
|
{plan.price}
|
||||||
</span>
|
</span>
|
||||||
<span style={{
|
<span style={{
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor,
|
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b',
|
||||||
}}>
|
}}>
|
||||||
{plan.period}
|
{plan.period}
|
||||||
</span>
|
</span>
|
||||||
@@ -193,12 +161,12 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
{(Array.isArray(plan.features) ? plan.features : []).map((feature, fi) => (
|
{(Array.isArray(plan.features) ? plan.features : []).map((feature, fi) => (
|
||||||
<li key={fi} style={{
|
<li key={fi} style={{
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor,
|
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
gap: '8px',
|
gap: '8px',
|
||||||
}}>
|
}}>
|
||||||
<span style={{ color: plan.isFeatured ? '#bbf7d0' : regCheckColor, fontWeight: '700' }}>{bulletChars[bulletType] || '✓'}</span>
|
<span style={{ color: plan.isFeatured ? '#bbf7d0' : '#10b981', fontWeight: '700' }}>{bulletChars[bulletType] || '✓'}</span>
|
||||||
{feature}
|
{feature}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@@ -210,8 +178,8 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
marginTop: 'auto',
|
marginTop: 'auto',
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
padding: '14px 32px',
|
padding: '14px 32px',
|
||||||
backgroundColor: plan.isFeatured ? '#ffffff' : regBtnBg,
|
backgroundColor: plan.isFeatured ? '#ffffff' : featuredBg,
|
||||||
color: plan.isFeatured ? featuredBg : regBtnColor,
|
color: plan.isFeatured ? featuredBg : '#ffffff',
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
@@ -239,18 +207,6 @@ PricingTable.craft = {
|
|||||||
featuredBg: '#3b82f6',
|
featuredBg: '#3b82f6',
|
||||||
bulletType: 'check',
|
bulletType: 'check',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
cardBg: '',
|
|
||||||
textColor: '',
|
|
||||||
subColor: '',
|
|
||||||
featColor: '',
|
|
||||||
checkColor: '',
|
|
||||||
btnBg: '',
|
|
||||||
btnColor: '',
|
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -272,28 +228,16 @@ PricingTable.craft = {
|
|||||||
// Sanitized -- featuredBg is a raw string-interpolation sink below (drives
|
// Sanitized -- featuredBg is a raw string-interpolation sink below (drives
|
||||||
// cardBg/btnBg/btnColor, all raw-interpolated into style="...").
|
// cardBg/btnBg/btnColor, all raw-interpolated into style="...").
|
||||||
const featuredBg = cssValue(props.featuredBg) || '#3b82f6';
|
const featuredBg = cssValue(props.featuredBg) || '#3b82f6';
|
||||||
// Sanitized -- regular (non-featured) card color overrides, all raw
|
|
||||||
// string-interpolation sinks into style="..." below. Each falls back to
|
|
||||||
// the exact literal the card was previously hard-coded to (or, for the
|
|
||||||
// button, to featuredBg) when unset, so unmodified pricing tables render
|
|
||||||
// identically to before these props existed.
|
|
||||||
const regCardBg = cssValue(props.cardBg) || '#ffffff';
|
|
||||||
const regTextColor = cssValue(props.textColor) || '#18181b';
|
|
||||||
const regSubColor = cssValue(props.subColor) || '#64748b';
|
|
||||||
const regFeatColor = cssValue(props.featColor) || '#4b5563';
|
|
||||||
const regCheckColor = cssValue(props.checkColor) || '#10b981';
|
|
||||||
const regBtnBg = cssValue(props.btnBg) || featuredBg;
|
|
||||||
const regBtnColor = cssValue(props.btnColor) || '#ffffff';
|
|
||||||
|
|
||||||
const cards = plans.map((plan) => {
|
const cards = plans.map((plan) => {
|
||||||
const cardBg = plan.isFeatured ? featuredBg : regCardBg;
|
const cardBg = plan.isFeatured ? featuredBg : '#ffffff';
|
||||||
const cardBorder = plan.isFeatured ? 'border:none;' : 'border:1px solid #e2e8f0;';
|
const cardBorder = plan.isFeatured ? 'border:none;' : 'border:1px solid #e2e8f0;';
|
||||||
const textColor = plan.isFeatured ? '#ffffff' : regTextColor;
|
const textColor = plan.isFeatured ? '#ffffff' : '#18181b';
|
||||||
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor;
|
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b';
|
||||||
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor;
|
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563';
|
||||||
const checkColor = plan.isFeatured ? '#bbf7d0' : regCheckColor;
|
const checkColor = plan.isFeatured ? '#bbf7d0' : '#10b981';
|
||||||
const btnBg = plan.isFeatured ? '#ffffff' : regBtnBg;
|
const btnBg = plan.isFeatured ? '#ffffff' : featuredBg;
|
||||||
const btnColor = plan.isFeatured ? featuredBg : regBtnColor;
|
const btnColor = plan.isFeatured ? featuredBg : '#ffffff';
|
||||||
const scale = plan.isFeatured ? 'transform:scale(1.05);' : '';
|
const scale = plan.isFeatured ? 'transform:scale(1.05);' : '';
|
||||||
const shadow = plan.isFeatured ? 'box-shadow:0 20px 60px rgba(59,130,246,0.3);' : 'box-shadow:0 1px 3px rgba(0,0,0,0.06);';
|
const shadow = plan.isFeatured ? 'box-shadow:0 20px 60px rgba(59,130,246,0.3);' : 'box-shadow:0 1px 3px rgba(0,0,0,0.06);';
|
||||||
|
|
||||||
|
|||||||
@@ -80,14 +80,3 @@ describe('Tabs.toHtml deterministic + unique ids (thread node id, resolves id-co
|
|||||||
expect(html1).toBe(html2);
|
expect(html1).toBe(html2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Tabs.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (Tabs as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -17,11 +17,6 @@ interface TabsProps {
|
|||||||
inactiveTabColor?: string;
|
inactiveTabColor?: string;
|
||||||
contentBg?: string;
|
contentBg?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTabs: TabItem[] = [
|
const defaultTabs: TabItem[] = [
|
||||||
@@ -119,11 +114,6 @@ Tabs.craft = {
|
|||||||
inactiveTabColor: '#64748b',
|
inactiveTabColor: '#64748b',
|
||||||
contentBg: '#ffffff',
|
contentBg: '#ffffff',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -71,14 +71,3 @@ describe('Testimonials.toHtml rating aria-label sink (attacker-controlled `ratin
|
|||||||
expect(html).toContain('aria-label="Rating: 4 out of 5"');
|
expect(html).toContain('aria-label="Rating: 4 out of 5"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Testimonials.craft.props includes the box-model/animation/visibility rollout props', () => {
|
|
||||||
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
|
||||||
const props = (Testimonials as any).craft.props;
|
|
||||||
expect(props).toHaveProperty('animation', '');
|
|
||||||
expect(props).toHaveProperty('animationDelay', '');
|
|
||||||
expect(props).toHaveProperty('hideOnDesktop', false);
|
|
||||||
expect(props).toHaveProperty('hideOnTablet', false);
|
|
||||||
expect(props).toHaveProperty('hideOnMobile', false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ interface TestimonialsProps {
|
|||||||
cardBg?: string;
|
cardBg?: string;
|
||||||
starColor?: string;
|
starColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTestimonials: Testimonial[] = [
|
const defaultTestimonials: Testimonial[] = [
|
||||||
@@ -136,11 +131,6 @@ Testimonials.craft = {
|
|||||||
cardBg: '#f8fafc',
|
cardBg: '#f8fafc',
|
||||||
starColor: '#f59e0b',
|
starColor: '#f59e0b',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -2,30 +2,28 @@ import React, { CSSProperties } from 'react';
|
|||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
import {
|
import {
|
||||||
IMAGE_RADIUS_PRESETS,
|
IMAGE_RADIUS_PRESETS,
|
||||||
|
OBJECT_FIT,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
SectionLabel,
|
SectionLabel,
|
||||||
PresetButtonGrid,
|
PresetButtonGrid,
|
||||||
TextInputField,
|
TextInputField,
|
||||||
|
SizeControl,
|
||||||
|
AspectRatioControl,
|
||||||
|
FocalPointGrid,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { AssetPicker } from '../../../ui/AssetPicker';
|
import { AssetPicker } from '../../../ui/AssetPicker';
|
||||||
import { PLACEHOLDER_SRC } from '../../../components/media/ImageBlock';
|
import { PLACEHOLDER_SRC } from '../../../components/media/ImageBlock';
|
||||||
|
import { BoxModelSection, BorderEffectsSection, AnimVisSection } from './mediaBoxModel';
|
||||||
|
|
||||||
/* ---------- IMAGE (with upload/browse/drop) ---------- */
|
/* ---------- IMAGE (with upload/browse/drop) ---------- */
|
||||||
export const ImageStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const ImageStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
const style: CSSProperties = nodeProps.style || {};
|
const style: CSSProperties = nodeProps.style || {};
|
||||||
|
|
||||||
const { setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
|
|
||||||
const maxWidthPresets = [
|
|
||||||
{ label: '25%', value: '25%' },
|
|
||||||
{ label: '50%', value: '50%' },
|
|
||||||
{ label: '75%', value: '75%' },
|
|
||||||
{ label: '100%', value: '100%' },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -49,6 +47,39 @@ export const ImageStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePro
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Size -- Width absorbs the historical maxWidth presets (25/50/75/100%
|
||||||
|
are a subset of SizeControl's default preset row), Height is new. */}
|
||||||
|
<SizeControl
|
||||||
|
label="Width"
|
||||||
|
value={(style.maxWidth as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('maxWidth', v)}
|
||||||
|
/>
|
||||||
|
<SizeControl
|
||||||
|
label="Height"
|
||||||
|
value={(style.height as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('height', v)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Crop & Framing -- aspect-ratio + object-fit + object-position on the
|
||||||
|
<img> itself is a CSS framing crop (no server-side image processing
|
||||||
|
needed). */}
|
||||||
|
<AspectRatioControl
|
||||||
|
value={(style.aspectRatio as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('aspectRatio', v)}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Object Fit</SectionLabel>
|
||||||
|
<PresetButtonGrid
|
||||||
|
presets={OBJECT_FIT}
|
||||||
|
activeValue={(style.objectFit as string) || ''}
|
||||||
|
onSelect={(v) => setPropStyle('objectFit', v)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FocalPointGrid
|
||||||
|
value={(style.objectPosition as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('objectPosition', v)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Border Radius */}
|
{/* Border Radius */}
|
||||||
<div className="guided-section">
|
<div className="guided-section">
|
||||||
<SectionLabel>Border Radius</SectionLabel>
|
<SectionLabel>Border Radius</SectionLabel>
|
||||||
@@ -59,15 +90,10 @@ export const ImageStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePro
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Max Width */}
|
{/* Box model + animation/visibility rollout */}
|
||||||
<div className="guided-section">
|
<BoxModelSection style={style} setPropStyle={setPropStyle} />
|
||||||
<SectionLabel>Max Width</SectionLabel>
|
<BorderEffectsSection style={style} setPropStyle={setPropStyle} />
|
||||||
<PresetButtonGrid
|
<AnimVisSection nodeProps={nodeProps} setProp={setProp} />
|
||||||
presets={maxWidthPresets}
|
|
||||||
activeValue={style.maxWidth as string}
|
|
||||||
onSelect={(v) => setPropStyle('maxWidth', v)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React from 'react';
|
|||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
import {
|
import {
|
||||||
BG_COLORS,
|
BG_COLORS,
|
||||||
SPACING_PRESETS,
|
|
||||||
RADIUS_PRESETS,
|
RADIUS_PRESETS,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +12,8 @@ import {
|
|||||||
CollapsibleSection,
|
CollapsibleSection,
|
||||||
ColorPickerField,
|
ColorPickerField,
|
||||||
ArrayPropEditor,
|
ArrayPropEditor,
|
||||||
|
SizeControl,
|
||||||
|
AspectRatioControl,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
inputStyle,
|
inputStyle,
|
||||||
smallInputStyle,
|
smallInputStyle,
|
||||||
@@ -20,6 +21,14 @@ import {
|
|||||||
useNodeProp,
|
useNodeProp,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { AssetPicker } from '../../../ui/AssetPicker';
|
import { AssetPicker } from '../../../ui/AssetPicker';
|
||||||
|
import { BoxModelSection, BorderEffectsSection, AnimVisSection } from './mediaBoxModel';
|
||||||
|
|
||||||
|
const GALLERY_COLUMN_PRESETS = [
|
||||||
|
{ label: '2', value: '2' },
|
||||||
|
{ label: '3', value: '3' },
|
||||||
|
{ label: '4', value: '4' },
|
||||||
|
{ label: '5', value: '5' },
|
||||||
|
];
|
||||||
|
|
||||||
/* ---------- MEDIA (Video / Gallery / Map / Slider) ---------- */
|
/* ---------- MEDIA (Video / Gallery / Map / Slider) ---------- */
|
||||||
export const MediaStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const MediaStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
@@ -30,11 +39,48 @@ export const MediaStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePro
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Video URL */}
|
{/* Video source -- upload/browse/paste-URL (paste-URL still handles
|
||||||
|
YouTube/Vimeo; upload/browse handle files via detectVideoType's
|
||||||
|
serve_asset resolution). */}
|
||||||
{nodeProps.videoUrl !== undefined && (
|
{nodeProps.videoUrl !== undefined && (
|
||||||
<div style={sectionGap}>
|
<div className="guided-section">
|
||||||
<label style={labelStyle}>Video URL</label>
|
<SectionLabel>Video Source</SectionLabel>
|
||||||
<input type="text" value={nodeProps.videoUrl || ''} onChange={(e) => setProp('videoUrl', e.target.value)} placeholder="YouTube, Vimeo, or .mp4 URL" style={inputStyle} />
|
<AssetPicker
|
||||||
|
mediaType="video"
|
||||||
|
value={nodeProps.videoUrl || ''}
|
||||||
|
onChange={(url) => setProp('videoUrl', url)}
|
||||||
|
variant="full"
|
||||||
|
placeholder="Or paste a YouTube/Vimeo/.mp4 URL..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Video size -- width + aspect ratio for the video frame. */}
|
||||||
|
{nodeProps.videoUrl !== undefined && (
|
||||||
|
<>
|
||||||
|
<SizeControl
|
||||||
|
label="Width"
|
||||||
|
value={(style.width as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('width', v)}
|
||||||
|
/>
|
||||||
|
<AspectRatioControl
|
||||||
|
value={(style.aspectRatio as string) || ''}
|
||||||
|
onChange={(v) => setPropStyle('aspectRatio', v)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Poster image (optional, file-type videos only in practice but
|
||||||
|
harmless to offer whenever the component has a poster prop). */}
|
||||||
|
{nodeProps.poster !== undefined && (
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Poster Image (optional)</SectionLabel>
|
||||||
|
<AssetPicker
|
||||||
|
mediaType="image"
|
||||||
|
value={nodeProps.poster || ''}
|
||||||
|
onChange={(url) => setProp('poster', url)}
|
||||||
|
variant="full"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -80,6 +126,26 @@ export const MediaStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePro
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Gallery layout -- columns + lightbox (existing-but-previously-unexposed props). */}
|
||||||
|
{nodeProps.images !== undefined && Array.isArray(nodeProps.images) && (
|
||||||
|
<>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Columns</SectionLabel>
|
||||||
|
<PresetButtonGrid
|
||||||
|
presets={GALLERY_COLUMN_PRESETS}
|
||||||
|
activeValue={String(nodeProps.columns ?? 3)}
|
||||||
|
onSelect={(v) => setProp('columns', Number(v))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={{ ...labelStyle, display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer' }}>
|
||||||
|
<input type="checkbox" checked={!!nodeProps.lightbox} onChange={(e) => setProp('lightbox', e.target.checked)} />
|
||||||
|
Enable Lightbox
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Gallery items */}
|
{/* Gallery items */}
|
||||||
{nodeProps.images !== undefined && Array.isArray(nodeProps.images) && (
|
{nodeProps.images !== undefined && Array.isArray(nodeProps.images) && (
|
||||||
<CollapsibleSection title="Images">
|
<CollapsibleSection title="Images">
|
||||||
@@ -178,21 +244,23 @@ export const MediaStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePro
|
|||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Background & padding */}
|
{/* Background & radius */}
|
||||||
<CollapsibleSection title="Style" defaultOpen={false}>
|
<CollapsibleSection title="Style" defaultOpen={false}>
|
||||||
<div className="guided-section">
|
<div className="guided-section">
|
||||||
<SectionLabel>Background</SectionLabel>
|
<SectionLabel>Background</SectionLabel>
|
||||||
<ColorSwatchGrid colors={BG_COLORS} activeValue={style.backgroundColor} onSelect={(v: string) => setPropStyle('backgroundColor', v)} />
|
<ColorSwatchGrid colors={BG_COLORS} activeValue={style.backgroundColor} onSelect={(v: string) => setPropStyle('backgroundColor', v)} />
|
||||||
</div>
|
</div>
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Padding</SectionLabel>
|
|
||||||
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={style.padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
|
||||||
</div>
|
|
||||||
<div className="guided-section">
|
<div className="guided-section">
|
||||||
<SectionLabel>Border Radius</SectionLabel>
|
<SectionLabel>Border Radius</SectionLabel>
|
||||||
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Box model + animation/visibility rollout (Video/Gallery/Map/Slider
|
||||||
|
all carry these props now, so it's safe to render unconditionally). */}
|
||||||
|
<BoxModelSection style={style} setPropStyle={setPropStyle} />
|
||||||
|
<BorderEffectsSection style={style} setPropStyle={setPropStyle} />
|
||||||
|
<AnimVisSection nodeProps={nodeProps} setProp={setProp} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
|
import React from 'react';
|
||||||
|
import { createRoot, Root } from 'react-dom/client';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
|
/* Same DOM-harness pattern as MediaStylePanel.slides.test.tsx -- mock
|
||||||
|
@craftjs/core's useEditor so setProp calls can be observed without
|
||||||
|
mounting a real <Editor> tree, and mock utils/assets so AssetPicker
|
||||||
|
doesn't hit the network. */
|
||||||
|
const setPropSpy = vi.fn((_id: string, updater: (p: any) => void) => {
|
||||||
|
updater(lastProps);
|
||||||
|
});
|
||||||
|
let lastProps: any;
|
||||||
|
|
||||||
|
vi.mock('@craftjs/core', () => ({
|
||||||
|
useEditor: () => ({ actions: { setProp: setPropSpy } }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../../utils/assets', () => ({
|
||||||
|
uploadAsset: vi.fn(),
|
||||||
|
listAssets: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { MediaStylePanel } from './MediaStylePanel';
|
||||||
|
|
||||||
|
let container: HTMLDivElement;
|
||||||
|
let root: Root;
|
||||||
|
|
||||||
|
function render(ui: React.ReactElement) {
|
||||||
|
container = document.createElement('div');
|
||||||
|
document.body.appendChild(container);
|
||||||
|
act(() => {
|
||||||
|
root = createRoot(container);
|
||||||
|
root.render(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount() {
|
||||||
|
act(() => { root.unmount(); });
|
||||||
|
container.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function q<T extends Element = Element>(testId: string): T | null {
|
||||||
|
return container.querySelector(`[data-testid="${testId}"]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function qAll<T extends Element = Element>(testId: string): T[] {
|
||||||
|
return Array.from(container.querySelectorAll(`[data-testid="${testId}"]`));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setValue(input: HTMLInputElement, value: string) {
|
||||||
|
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')!.set!;
|
||||||
|
setter.call(input, value);
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setPropSpy.mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (container) unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('MediaStylePanel Video source uses AssetPicker (upload/browse/paste-URL), not a plain text input', () => {
|
||||||
|
test('renders a full-variant AssetPicker (not the old plain input) for videoUrl', () => {
|
||||||
|
lastProps = { videoUrl: '', poster: '', style: {} };
|
||||||
|
render(<MediaStylePanel selectedId="vid-1" nodeProps={lastProps} />);
|
||||||
|
expect(q('asset-picker-full')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('applying a pasted URL via the AssetPicker writes videoUrl (not some other key)', () => {
|
||||||
|
lastProps = { videoUrl: '', poster: '', style: {} };
|
||||||
|
render(<MediaStylePanel selectedId="vid-1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
// The Video Source AssetPicker is the first url-input on the page (the
|
||||||
|
// Poster picker is a second, separate AssetPicker instance below it).
|
||||||
|
const urlInput = qAll<HTMLInputElement>('asset-picker-url-input')[0];
|
||||||
|
expect(urlInput).toBeTruthy();
|
||||||
|
setValue(urlInput, 'https://example.com/clip.mp4');
|
||||||
|
|
||||||
|
const applyBtn = qAll<HTMLButtonElement>('asset-picker-apply')[0];
|
||||||
|
act(() => {
|
||||||
|
applyBtn.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(setPropSpy).toHaveBeenCalled();
|
||||||
|
expect(lastProps.videoUrl).toBe('https://example.com/clip.mp4');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a video-shaped selection also renders a Poster AssetPicker (image) that writes `poster`', () => {
|
||||||
|
lastProps = { videoUrl: 'https://example.com/clip.mp4', poster: '', style: {} };
|
||||||
|
render(<MediaStylePanel selectedId="vid-1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
const pickers = qAll('asset-picker-full');
|
||||||
|
expect(pickers.length).toBe(2); // Video Source + Poster Image
|
||||||
|
|
||||||
|
const urlInputs = qAll<HTMLInputElement>('asset-picker-url-input');
|
||||||
|
const posterInput = urlInputs[1];
|
||||||
|
setValue(posterInput, 'https://example.com/poster.jpg');
|
||||||
|
const applyBtns = qAll<HTMLButtonElement>('asset-picker-apply');
|
||||||
|
act(() => {
|
||||||
|
applyBtns[1].dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(lastProps.poster).toBe('https://example.com/poster.jpg');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('MediaStylePanel Video size controls (Width + Aspect Ratio) are gated on videoUrl', () => {
|
||||||
|
test('a video-shaped selection renders SizeControl + AspectRatioControl', () => {
|
||||||
|
lastProps = { videoUrl: '', poster: '', style: {} };
|
||||||
|
render(<MediaStylePanel selectedId="vid-1" nodeProps={lastProps} />);
|
||||||
|
expect(q('size-control')).not.toBeNull();
|
||||||
|
expect(q('aspect-ratio-control')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a Map-shaped selection (no videoUrl) does NOT render the video size controls', () => {
|
||||||
|
lastProps = { address: 'New York, NY', zoom: 14, height: '400px', style: {} };
|
||||||
|
render(<MediaStylePanel selectedId="map-1" nodeProps={lastProps} />);
|
||||||
|
expect(q('size-control')).toBeNull();
|
||||||
|
expect(q('aspect-ratio-control')).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function openCollapsibleByTitle(title: string) {
|
||||||
|
const btn = Array.from(container.querySelectorAll('button')).find((b) => b.textContent?.includes(title));
|
||||||
|
expect(btn).toBeTruthy();
|
||||||
|
act(() => {
|
||||||
|
btn!.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('MediaStylePanel box-model + animation/visibility rollout renders for every media type', () => {
|
||||||
|
test('a Map-shaped selection still gets Spacing / Border & Effects / Animation & Visibility sections (collapsed by default, open on click)', () => {
|
||||||
|
lastProps = { address: 'New York, NY', zoom: 14, height: '400px', style: {}, animation: '', hideOnDesktop: false };
|
||||||
|
render(<MediaStylePanel selectedId="map-1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
openCollapsibleByTitle('Spacing');
|
||||||
|
expect(q('spacing-control')).not.toBeNull();
|
||||||
|
|
||||||
|
openCollapsibleByTitle('Border & Effects');
|
||||||
|
expect(q('border-control')).not.toBeNull();
|
||||||
|
|
||||||
|
openCollapsibleByTitle('Animation & Visibility');
|
||||||
|
expect(q('animation-control')).not.toBeNull();
|
||||||
|
expect(q('visibility-control')).not.toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,38 +1,16 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
import { SHADOW_PRESETS } from '../../../constants/presets';
|
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
CollapsibleSection,
|
CollapsibleSection,
|
||||||
ColorPickerField,
|
ColorPickerField,
|
||||||
SectionLabel,
|
|
||||||
PresetButtonGrid,
|
|
||||||
labelStyle,
|
labelStyle,
|
||||||
inputStyle,
|
inputStyle,
|
||||||
smallInputStyle,
|
smallInputStyle,
|
||||||
btnActiveStyle,
|
btnActiveStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
|
||||||
SpacingControl,
|
|
||||||
BorderControl,
|
|
||||||
BorderValue,
|
|
||||||
buildBorderShorthand,
|
|
||||||
AnimationControl,
|
|
||||||
VisibilityControl,
|
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
/** Parses a border shorthand string ("2px solid #hex") produced by
|
|
||||||
* buildBorderShorthand() back into its parts for round-tripping through
|
|
||||||
* BorderControl. See SectionTypePanel.tsx for the identical helper. */
|
|
||||||
function parseBorderShorthand(v: string | undefined): BorderValue {
|
|
||||||
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
|
||||||
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
|
||||||
if (!m) return { width: '', style: 'none', color: '#000000' };
|
|
||||||
return { width: m[1], style: m[2], color: m[3] };
|
|
||||||
}
|
|
||||||
|
|
||||||
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
|
||||||
|
|
||||||
const bulletOptions = [
|
const bulletOptions = [
|
||||||
{ label: '✓', value: 'check' },
|
{ label: '✓', value: 'check' },
|
||||||
{ label: '●', value: 'dot' },
|
{ label: '●', value: 'dot' },
|
||||||
@@ -48,12 +26,10 @@ const bulletChar: Record<string, string> = {
|
|||||||
|
|
||||||
export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
|
||||||
const [expandedPlan, setExpandedPlan] = useState<number>(0);
|
const [expandedPlan, setExpandedPlan] = useState<number>(0);
|
||||||
|
|
||||||
const plans: any[] = Array.isArray(nodeProps.plans) ? nodeProps.plans : [];
|
const plans: any[] = Array.isArray(nodeProps.plans) ? nodeProps.plans : [];
|
||||||
const currentBullet = nodeProps.bulletType || 'check';
|
const currentBullet = nodeProps.bulletType || 'check';
|
||||||
const style = nodeProps.style || {};
|
|
||||||
|
|
||||||
const updatePlan = useCallback((planIndex: number, field: string, value: any) => {
|
const updatePlan = useCallback((planIndex: number, field: string, value: any) => {
|
||||||
actions.setProp(selectedId, (props: any) => {
|
actions.setProp(selectedId, (props: any) => {
|
||||||
@@ -228,79 +204,6 @@ export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeP
|
|||||||
{/* Colors */}
|
{/* Colors */}
|
||||||
<CollapsibleSection title="Colors" defaultOpen={false}>
|
<CollapsibleSection title="Colors" defaultOpen={false}>
|
||||||
<ColorPickerField label="Featured Plan Color" value={nodeProps.featuredBg || '#3b82f6'} onChange={(v) => actions.setProp(selectedId, (p: any) => { p.featuredBg = v; })} />
|
<ColorPickerField label="Featured Plan Color" value={nodeProps.featuredBg || '#3b82f6'} onChange={(v) => actions.setProp(selectedId, (p: any) => { p.featuredBg = v; })} />
|
||||||
{/* Regular (non-featured) card colors -- built into PricingTable's
|
|
||||||
render/toHtml but previously hard-coded literals with no control
|
|
||||||
surfacing them. Each falls back to the prior literal when blank. */}
|
|
||||||
<ColorPickerField label="Card Background" value={nodeProps.cardBg || '#ffffff'} onChange={(v) => setProp('cardBg', v)} />
|
|
||||||
<ColorPickerField label="Heading / Price Color" value={nodeProps.textColor || '#18181b'} onChange={(v) => setProp('textColor', v)} />
|
|
||||||
<ColorPickerField label="Period Text Color" value={nodeProps.subColor || '#64748b'} onChange={(v) => setProp('subColor', v)} />
|
|
||||||
<ColorPickerField label="Feature Text Color" value={nodeProps.featColor || '#4b5563'} onChange={(v) => setProp('featColor', v)} />
|
|
||||||
<ColorPickerField label="Checkmark Color" value={nodeProps.checkColor || '#10b981'} onChange={(v) => setProp('checkColor', v)} />
|
|
||||||
<ColorPickerField label="Button Background" value={nodeProps.btnBg || nodeProps.featuredBg || '#3b82f6'} onChange={(v) => setProp('btnBg', v)} />
|
|
||||||
<ColorPickerField label="Button Text Color" value={nodeProps.btnColor || '#ffffff'} onChange={(v) => setProp('btnColor', v)} />
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Box model: margin, padding, border, shadow, opacity */}
|
|
||||||
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
|
||||||
<SpacingControl
|
|
||||||
label="Margin"
|
|
||||||
value={{
|
|
||||||
top: style.marginTop as string, right: style.marginRight as string,
|
|
||||||
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<SpacingControl
|
|
||||||
label="Padding"
|
|
||||||
value={{
|
|
||||||
top: style.paddingTop as string, right: style.paddingRight as string,
|
|
||||||
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<BorderControl
|
|
||||||
value={parseBorderShorthand(style.border as string)}
|
|
||||||
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
|
||||||
/>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Shadow</SectionLabel>
|
|
||||||
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
|
||||||
</div>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Opacity</SectionLabel>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min={0}
|
|
||||||
max={100}
|
|
||||||
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
|
||||||
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Entrance animation */}
|
|
||||||
<CollapsibleSection title="Animation" defaultOpen={false}>
|
|
||||||
<AnimationControl
|
|
||||||
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
|
||||||
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Responsive visibility */}
|
|
||||||
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
|
||||||
<VisibilityControl
|
|
||||||
value={{
|
|
||||||
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
|
||||||
hideOnTablet: !!nodeProps.hideOnTablet,
|
|
||||||
hideOnMobile: !!nodeProps.hideOnMobile,
|
|
||||||
}}
|
|
||||||
onChange={(v) => {
|
|
||||||
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
|
||||||
setProp('hideOnTablet', !!v.hideOnTablet);
|
|
||||||
setProp('hideOnMobile', !!v.hideOnMobile);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
BG_COLORS,
|
BG_COLORS,
|
||||||
SPACING_PRESETS,
|
SPACING_PRESETS,
|
||||||
RADIUS_PRESETS,
|
RADIUS_PRESETS,
|
||||||
SHADOW_PRESETS,
|
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
@@ -16,31 +15,10 @@ import {
|
|||||||
inputStyle,
|
inputStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
SpacingControl,
|
|
||||||
BorderControl,
|
|
||||||
BorderValue,
|
|
||||||
buildBorderShorthand,
|
|
||||||
AnimationControl,
|
|
||||||
VisibilityControl,
|
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { FeaturesEditor } from './FeaturesEditor';
|
import { FeaturesEditor } from './FeaturesEditor';
|
||||||
import { ArrayItemFieldsEditor } from './ArrayItemFields';
|
import { ArrayItemFieldsEditor } from './ArrayItemFields';
|
||||||
|
|
||||||
/** Parses a border shorthand string ("2px solid #hex") produced by
|
|
||||||
* buildBorderShorthand() back into its parts for round-tripping through
|
|
||||||
* BorderControl. Anything that doesn't match (undefined/'none'/legacy
|
|
||||||
* hand-authored values) falls back to an empty/none border rather than
|
|
||||||
* throwing, since this is display-only -- the next edit always re-emits a
|
|
||||||
* clean shorthand via buildBorderShorthand(). */
|
|
||||||
function parseBorderShorthand(v: string | undefined): BorderValue {
|
|
||||||
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
|
||||||
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
|
||||||
if (!m) return { width: '', style: 'none', color: '#000000' };
|
|
||||||
return { width: m[1], style: m[2], color: m[3] };
|
|
||||||
}
|
|
||||||
|
|
||||||
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
|
||||||
|
|
||||||
/* ---------- SECTION-TYPE (Accordion, Tabs, Pricing, Testimonials, etc.) ---------- */
|
/* ---------- SECTION-TYPE (Accordion, Tabs, Pricing, Testimonials, etc.) ---------- */
|
||||||
export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }> = ({ selectedId, nodeProps, typeName }) => {
|
export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }> = ({ selectedId, nodeProps, typeName }) => {
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
@@ -48,12 +26,7 @@ export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }>
|
|||||||
const style = nodeProps.style || {};
|
const style = nodeProps.style || {};
|
||||||
|
|
||||||
// Find all string/number/boolean props
|
// Find all string/number/boolean props
|
||||||
const SKIP_PROPS = new Set([
|
const SKIP_PROPS = new Set(['style', 'children', 'cssId', 'cssClass']);
|
||||||
'style', 'children', 'cssId', 'cssClass',
|
|
||||||
// Rendered via dedicated controls below (Animation/Visibility), not the
|
|
||||||
// generic Content field dump -- otherwise they'd show up twice.
|
|
||||||
'animation', 'animationDelay', 'hideOnDesktop', 'hideOnTablet', 'hideOnMobile',
|
|
||||||
]);
|
|
||||||
const scalarProps = Object.entries(nodeProps).filter(
|
const scalarProps = Object.entries(nodeProps).filter(
|
||||||
([key, val]) => !SKIP_PROPS.has(key) && (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean')
|
([key, val]) => !SKIP_PROPS.has(key) && (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean')
|
||||||
);
|
);
|
||||||
@@ -153,69 +126,6 @@ export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }>
|
|||||||
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
{/* Box model: margin, padding, border, shadow, opacity */}
|
|
||||||
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
|
||||||
<SpacingControl
|
|
||||||
label="Margin"
|
|
||||||
value={{
|
|
||||||
top: style.marginTop as string, right: style.marginRight as string,
|
|
||||||
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<SpacingControl
|
|
||||||
label="Padding"
|
|
||||||
value={{
|
|
||||||
top: style.paddingTop as string, right: style.paddingRight as string,
|
|
||||||
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<BorderControl
|
|
||||||
value={parseBorderShorthand(style.border as string)}
|
|
||||||
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
|
||||||
/>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Shadow</SectionLabel>
|
|
||||||
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
|
||||||
</div>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Opacity</SectionLabel>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min={0}
|
|
||||||
max={100}
|
|
||||||
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
|
||||||
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Entrance animation */}
|
|
||||||
<CollapsibleSection title="Animation" defaultOpen={false}>
|
|
||||||
<AnimationControl
|
|
||||||
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
|
||||||
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Responsive visibility */}
|
|
||||||
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
|
||||||
<VisibilityControl
|
|
||||||
value={{
|
|
||||||
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
|
||||||
hideOnTablet: !!nodeProps.hideOnTablet,
|
|
||||||
hideOnMobile: !!nodeProps.hideOnMobile,
|
|
||||||
}}
|
|
||||||
onChange={(v) => {
|
|
||||||
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
|
||||||
setProp('hideOnTablet', !!v.hideOnTablet);
|
|
||||||
setProp('hideOnMobile', !!v.hideOnMobile);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { useEditor } from '@craftjs/core';
|
|||||||
import {
|
import {
|
||||||
BG_COLORS,
|
BG_COLORS,
|
||||||
SPACING_PRESETS,
|
SPACING_PRESETS,
|
||||||
SHADOW_PRESETS,
|
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
@@ -18,33 +17,8 @@ import {
|
|||||||
btnActiveStyle,
|
btnActiveStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
SpacingControl,
|
|
||||||
BorderControl,
|
|
||||||
BorderValue,
|
|
||||||
buildBorderShorthand,
|
|
||||||
AnimationControl,
|
|
||||||
VisibilityControl,
|
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
/** Parses a border shorthand string ("2px solid #hex") produced by
|
|
||||||
* buildBorderShorthand() back into its parts for round-tripping through
|
|
||||||
* BorderControl. See SectionTypePanel.tsx for the identical helper. */
|
|
||||||
function parseBorderShorthand(v: string | undefined): BorderValue {
|
|
||||||
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
|
||||||
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
|
||||||
if (!m) return { width: '', style: 'none', color: '#000000' };
|
|
||||||
return { width: m[1], style: m[2], color: m[3] };
|
|
||||||
}
|
|
||||||
|
|
||||||
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
|
||||||
|
|
||||||
const ICON_SHAPES = [
|
|
||||||
{ label: 'None', value: 'none' },
|
|
||||||
{ label: 'Circle', value: 'circle' },
|
|
||||||
{ label: 'Square', value: 'square' },
|
|
||||||
{ label: 'Rounded', value: 'rounded' },
|
|
||||||
];
|
|
||||||
|
|
||||||
/* ---------- SOCIAL / ICON / STAR RATING ---------- */
|
/* ---------- SOCIAL / ICON / STAR RATING ---------- */
|
||||||
export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
@@ -137,72 +111,6 @@ export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePr
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Icon shape (SocialLinks) -- exists on the component (iconShape prop
|
|
||||||
drives the circle/square/rounded background box) but previously had
|
|
||||||
no control. */}
|
|
||||||
{nodeProps.iconShape !== undefined && (
|
|
||||||
<div style={sectionGap}>
|
|
||||||
<label style={labelStyle}>Icon Shape</label>
|
|
||||||
<div style={{ display: 'flex', gap: 4 }}>
|
|
||||||
{ICON_SHAPES.map((s) => (
|
|
||||||
<button key={s.value} onClick={() => setProp('iconShape', s.value)} style={{ ...btnActiveStyle(nodeProps.iconShape === s.value), flex: 1 }}>
|
|
||||||
{s.label}
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* Gap between links (SocialLinks) -- exists on the component but
|
|
||||||
previously had no control. */}
|
|
||||||
{nodeProps.gap !== undefined && (
|
|
||||||
<div style={sectionGap}>
|
|
||||||
<label style={labelStyle}>Gap</label>
|
|
||||||
<input type="text" value={nodeProps.gap || '10px'} onChange={(e) => setProp('gap', e.target.value)} placeholder="10px" style={inputStyle} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Background shape / size / link (Icon component) -- bgColor, bgShape,
|
|
||||||
bgSize, link all already exist on Icon.craft.props but had no
|
|
||||||
control; the generic `color`/`iconColor` checks above never matched
|
|
||||||
Icon's actual prop names. */}
|
|
||||||
{nodeProps.bgShape !== undefined && (
|
|
||||||
<div style={sectionGap}>
|
|
||||||
<label style={labelStyle}>Background Shape</label>
|
|
||||||
<div style={{ display: 'flex', gap: 4 }}>
|
|
||||||
{ICON_SHAPES.map((s) => (
|
|
||||||
<button key={s.value} onClick={() => setProp('bgShape', s.value)} style={{ ...btnActiveStyle(nodeProps.bgShape === s.value), flex: 1 }}>
|
|
||||||
{s.label}
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{nodeProps.bgColor !== undefined && (
|
|
||||||
<ColorPickerField label="Background Color" value={nodeProps.bgColor === 'transparent' ? '' : nodeProps.bgColor} onChange={(v) => setProp('bgColor', v)} />
|
|
||||||
)}
|
|
||||||
{nodeProps.bgSize !== undefined && (
|
|
||||||
<div style={sectionGap}>
|
|
||||||
<label style={labelStyle}>Background Size</label>
|
|
||||||
<input type="text" value={nodeProps.bgSize || '56px'} onChange={(e) => setProp('bgSize', e.target.value)} placeholder="56px" style={inputStyle} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{nodeProps.link !== undefined && (
|
|
||||||
<div style={sectionGap}>
|
|
||||||
<label style={labelStyle}>Link URL</label>
|
|
||||||
<input type="text" value={nodeProps.link || ''} onChange={(e) => setProp('link', e.target.value)} placeholder="https://..." style={inputStyle} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Star colors (StarRating) -- exist on the component as filledColor /
|
|
||||||
emptyColor but had no control (the generic `starColor` check above
|
|
||||||
never matched StarRating's actual prop names). */}
|
|
||||||
{nodeProps.filledColor !== undefined && (
|
|
||||||
<ColorPickerField label="Filled Star Color" value={nodeProps.filledColor || '#f59e0b'} onChange={(v) => setProp('filledColor', v)} />
|
|
||||||
)}
|
|
||||||
{nodeProps.emptyColor !== undefined && (
|
|
||||||
<ColorPickerField label="Empty Star Color" value={nodeProps.emptyColor || '#d1d5db'} onChange={(v) => setProp('emptyColor', v)} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Colors */}
|
{/* Colors */}
|
||||||
{nodeProps.iconColor !== undefined && (
|
{nodeProps.iconColor !== undefined && (
|
||||||
<ColorPickerField label="Icon Color" value={nodeProps.iconColor || '#3b82f6'} onChange={(v) => setProp('iconColor', v)} />
|
<ColorPickerField label="Icon Color" value={nodeProps.iconColor || '#3b82f6'} onChange={(v) => setProp('iconColor', v)} />
|
||||||
@@ -256,69 +164,6 @@ export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePr
|
|||||||
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={style.padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={style.padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
{/* Box model: margin, padding (per-side), border, shadow, opacity */}
|
|
||||||
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
|
||||||
<SpacingControl
|
|
||||||
label="Margin"
|
|
||||||
value={{
|
|
||||||
top: style.marginTop as string, right: style.marginRight as string,
|
|
||||||
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<SpacingControl
|
|
||||||
label="Padding"
|
|
||||||
value={{
|
|
||||||
top: style.paddingTop as string, right: style.paddingRight as string,
|
|
||||||
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
|
||||||
}}
|
|
||||||
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
|
||||||
/>
|
|
||||||
<BorderControl
|
|
||||||
value={parseBorderShorthand(style.border as string)}
|
|
||||||
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
|
||||||
/>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Shadow</SectionLabel>
|
|
||||||
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
|
||||||
</div>
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Opacity</SectionLabel>
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min={0}
|
|
||||||
max={100}
|
|
||||||
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
|
||||||
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Entrance animation */}
|
|
||||||
<CollapsibleSection title="Animation" defaultOpen={false}>
|
|
||||||
<AnimationControl
|
|
||||||
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
|
||||||
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
|
||||||
|
|
||||||
{/* Responsive visibility */}
|
|
||||||
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
|
||||||
<VisibilityControl
|
|
||||||
value={{
|
|
||||||
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
|
||||||
hideOnTablet: !!nodeProps.hideOnTablet,
|
|
||||||
hideOnMobile: !!nodeProps.hideOnMobile,
|
|
||||||
}}
|
|
||||||
onChange={(v) => {
|
|
||||||
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
|
||||||
setProp('hideOnTablet', !!v.hideOnTablet);
|
|
||||||
setProp('hideOnMobile', !!v.hideOnMobile);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CollapsibleSection>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { SHADOW_PRESETS } from '../../../constants/presets';
|
||||||
|
import {
|
||||||
|
SectionLabel,
|
||||||
|
PresetButtonGrid,
|
||||||
|
CollapsibleSection,
|
||||||
|
SpacingControl,
|
||||||
|
SpacingSide,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
|
sectionGap,
|
||||||
|
labelStyle,
|
||||||
|
} from './shared';
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Shared box-model / border+effects / animation+visibility sections for the
|
||||||
|
MEDIA package's panels (ImageStylePanel + MediaStylePanel). Kept local to
|
||||||
|
this package (not in shared.tsx, which is foundation/import-only) since
|
||||||
|
it's just DRY-ing the identical JSX block across ImageBlock/VideoBlock/
|
||||||
|
Gallery/ContentSlider/MapEmbed rather than a genuinely cross-package
|
||||||
|
reusable control.
|
||||||
|
========================================================================== */
|
||||||
|
|
||||||
|
function capitalize(s: string): string {
|
||||||
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Parses a `border` shorthand string (e.g. "2px solid #ff0000") back into
|
||||||
|
* the {width,style,color} shape BorderControl edits. Only needs to
|
||||||
|
* round-trip values this same panel produced via buildBorderShorthand --
|
||||||
|
* not arbitrary author-supplied CSS. */
|
||||||
|
export function parseBorderShorthand(v: string | undefined): BorderValue {
|
||||||
|
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
||||||
|
const m = String(v).trim().match(/^(\d+(?:\.\d+)?(?:px|em|rem)?)\s+(\w+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '#000000' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoxModelSectionProps {
|
||||||
|
style: Record<string, any>;
|
||||||
|
setPropStyle: (prop: string, value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Margin + Padding, per-side, via the shared SpacingControl. */
|
||||||
|
export const BoxModelSection: React.FC<BoxModelSectionProps> = ({ style, setPropStyle }) => {
|
||||||
|
const sideSetter = (kind: 'margin' | 'padding') => (side: SpacingSide, value: string) =>
|
||||||
|
setPropStyle(`${kind}${capitalize(side)}`, value);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CollapsibleSection title="Spacing" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{ top: style.marginTop, right: style.marginRight, bottom: style.marginBottom, left: style.marginLeft }}
|
||||||
|
onChange={sideSetter('margin')}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding"
|
||||||
|
value={{ top: style.paddingTop, right: style.paddingRight, bottom: style.paddingBottom, left: style.paddingLeft }}
|
||||||
|
onChange={sideSetter('padding')}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** style.opacity is stored as a CSS-length-free numeric string ("0.8") or
|
||||||
|
* may be blank/undefined (treated as fully opaque). Converts to a 0-100
|
||||||
|
* integer for the range input / label. */
|
||||||
|
function opacityPercent(v: unknown): number {
|
||||||
|
if (v === undefined || v === null || v === '') return 100;
|
||||||
|
const n = parseFloat(String(v));
|
||||||
|
return Number.isFinite(n) ? Math.round(n * 100) : 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BorderEffectsSectionProps {
|
||||||
|
style: Record<string, any>;
|
||||||
|
setPropStyle: (prop: string, value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Border (width/style/color) + box-shadow preset + opacity slider. */
|
||||||
|
export const BorderEffectsSection: React.FC<BorderEffectsSectionProps> = ({ style, setPropStyle }) => (
|
||||||
|
<CollapsibleSection title="Border & Effects" defaultOpen={false}>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderShorthand(style.border)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Shadow</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
||||||
|
</div>
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Opacity: {opacityPercent(style.opacity)}%</label>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
value={opacityPercent(style.opacity)}
|
||||||
|
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CollapsibleSection>
|
||||||
|
);
|
||||||
|
|
||||||
|
export interface AnimVisSectionProps {
|
||||||
|
nodeProps: Record<string, any>;
|
||||||
|
setProp: (key: string, value: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Entrance animation + responsive hide toggles -- top-level props consumed
|
||||||
|
* directly by html-export.ts's buildDataAttrs (no toHtml change needed). */
|
||||||
|
export const AnimVisSection: React.FC<AnimVisSectionProps> = ({ nodeProps, setProp }) => (
|
||||||
|
<CollapsibleSection title="Animation & Visibility" defaultOpen={false}>
|
||||||
|
<AnimationControl
|
||||||
|
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay }}
|
||||||
|
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
||||||
|
/>
|
||||||
|
<VisibilityControl
|
||||||
|
value={{
|
||||||
|
hideOnDesktop: nodeProps.hideOnDesktop,
|
||||||
|
hideOnTablet: nodeProps.hideOnTablet,
|
||||||
|
hideOnMobile: nodeProps.hideOnMobile,
|
||||||
|
}}
|
||||||
|
onChange={(v) => {
|
||||||
|
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
||||||
|
setProp('hideOnTablet', !!v.hideOnTablet);
|
||||||
|
setProp('hideOnMobile', !!v.hideOnMobile);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user