Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88df4f2888 |
@@ -44,29 +44,3 @@ describe('Icon.toHtml XSS hardening', () => {
|
||||
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;
|
||||
link?: string;
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
function getBgBorderRadius(shape: string): string {
|
||||
@@ -101,11 +96,6 @@ Icon.craft = {
|
||||
bgSize: '56px',
|
||||
link: '',
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
|
||||
@@ -51,43 +51,3 @@ describe('SocialLinks.toHtml XSS hardening (iconSize/iconColor/iconBgColor/gap i
|
||||
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;
|
||||
alignment?: 'left' | 'center' | 'right';
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const platformIcons: Record<string, string> = {
|
||||
@@ -156,11 +151,6 @@ SocialLinks.craft = {
|
||||
gap: '10px',
|
||||
alignment: 'center',
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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"/);
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
emptyColor?: string;
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
export const StarRating: UserComponent<StarRatingProps> = ({
|
||||
@@ -92,11 +87,6 @@ StarRating.craft = {
|
||||
filledColor: '#f59e0b',
|
||||
emptyColor: '#d1d5db',
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
|
||||
@@ -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;
|
||||
borderColor?: string;
|
||||
anchorId?: string;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultItems: AccordionItem[] = [
|
||||
@@ -140,11 +135,6 @@ Accordion.craft = {
|
||||
contentBg: '#ffffff',
|
||||
borderColor: '#e2e8f0',
|
||||
anchorId: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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;
|
||||
anchorId?: string;
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||
@@ -88,11 +83,6 @@ CTASection.craft = {
|
||||
gradient: defaultGradient,
|
||||
anchorId: '',
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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;
|
||||
anchorId?: string;
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||
@@ -136,11 +131,6 @@ CallToAction.craft = {
|
||||
textColor: '#ffffff',
|
||||
buttonColor: '#ffffff',
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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*\{/);
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
bgColor?: string;
|
||||
anchorId?: string;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
interface TimeLeft {
|
||||
@@ -144,11 +139,6 @@ Countdown.craft = {
|
||||
labelColor: 'rgba(255,255,255,0.7)',
|
||||
bgColor: '#18181b',
|
||||
anchorId: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
|
||||
@@ -21,14 +21,3 @@ describe('FeaturesGrid.toHtml image sink uses safeImageUrl (data:image/svg+xml a
|
||||
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[];
|
||||
style?: CSSProperties;
|
||||
anchorId?: string;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
// Keys image/imageAlt/buttonText/buttonUrl are present (blank) on the defaults so
|
||||
@@ -103,11 +98,6 @@ FeaturesGrid.craft = {
|
||||
features: defaultFeatures,
|
||||
style: { backgroundColor: '#ffffff' },
|
||||
anchorId: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
|
||||
@@ -73,14 +73,3 @@ describe('NumberCounter.toHtml counter.number is NOT runtime-type-checked -- mus
|
||||
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;
|
||||
numberSize?: string;
|
||||
style?: CSSProperties;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultCounters: Counter[] = [
|
||||
@@ -104,11 +99,6 @@ NumberCounter.craft = {
|
||||
labelColor: '#6b7280',
|
||||
numberSize: '48px',
|
||||
style: { backgroundColor: '#ffffff' },
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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;
|
||||
bulletType?: 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> = {
|
||||
@@ -78,13 +61,6 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
featuredBg = '#3b82f6',
|
||||
bulletType = 'check',
|
||||
anchorId,
|
||||
cardBg,
|
||||
textColor,
|
||||
subColor,
|
||||
featColor,
|
||||
checkColor,
|
||||
btnBg,
|
||||
btnColor,
|
||||
}) => {
|
||||
const {
|
||||
connectors: { connect, drag },
|
||||
@@ -93,14 +69,6 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
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 (
|
||||
<section
|
||||
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||
@@ -127,7 +95,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
style={{
|
||||
flex: '1 1 280px',
|
||||
maxWidth: '360px',
|
||||
backgroundColor: plan.isFeatured ? featuredBg : regCardBg,
|
||||
backgroundColor: plan.isFeatured ? featuredBg : '#ffffff',
|
||||
border: plan.isFeatured ? 'none' : '1px solid #e2e8f0',
|
||||
borderRadius: '16px',
|
||||
padding: '40px 32px',
|
||||
@@ -159,7 +127,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
<h3 style={{
|
||||
fontSize: '20px',
|
||||
fontWeight: '600',
|
||||
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
||||
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
||||
marginBottom: '8px',
|
||||
marginTop: plan.isFeatured ? '8px' : '0',
|
||||
}}>
|
||||
@@ -169,14 +137,14 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
<span style={{
|
||||
fontSize: '48px',
|
||||
fontWeight: '700',
|
||||
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
||||
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
||||
lineHeight: '1',
|
||||
}}>
|
||||
{plan.price}
|
||||
</span>
|
||||
<span style={{
|
||||
fontSize: '16px',
|
||||
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor,
|
||||
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b',
|
||||
}}>
|
||||
{plan.period}
|
||||
</span>
|
||||
@@ -193,12 +161,12 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
{(Array.isArray(plan.features) ? plan.features : []).map((feature, fi) => (
|
||||
<li key={fi} style={{
|
||||
fontSize: '14px',
|
||||
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor,
|
||||
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
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}
|
||||
</li>
|
||||
))}
|
||||
@@ -210,8 +178,8 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
||||
marginTop: 'auto',
|
||||
display: 'inline-block',
|
||||
padding: '14px 32px',
|
||||
backgroundColor: plan.isFeatured ? '#ffffff' : regBtnBg,
|
||||
color: plan.isFeatured ? featuredBg : regBtnColor,
|
||||
backgroundColor: plan.isFeatured ? '#ffffff' : featuredBg,
|
||||
color: plan.isFeatured ? featuredBg : '#ffffff',
|
||||
textDecoration: 'none',
|
||||
borderRadius: '8px',
|
||||
fontWeight: '600',
|
||||
@@ -239,18 +207,6 @@ PricingTable.craft = {
|
||||
featuredBg: '#3b82f6',
|
||||
bulletType: 'check',
|
||||
anchorId: '',
|
||||
cardBg: '',
|
||||
textColor: '',
|
||||
subColor: '',
|
||||
featColor: '',
|
||||
checkColor: '',
|
||||
btnBg: '',
|
||||
btnColor: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
@@ -272,28 +228,16 @@ PricingTable.craft = {
|
||||
// Sanitized -- featuredBg is a raw string-interpolation sink below (drives
|
||||
// cardBg/btnBg/btnColor, all raw-interpolated into style="...").
|
||||
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 cardBg = plan.isFeatured ? featuredBg : regCardBg;
|
||||
const cardBg = plan.isFeatured ? featuredBg : '#ffffff';
|
||||
const cardBorder = plan.isFeatured ? 'border:none;' : 'border:1px solid #e2e8f0;';
|
||||
const textColor = plan.isFeatured ? '#ffffff' : regTextColor;
|
||||
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor;
|
||||
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor;
|
||||
const checkColor = plan.isFeatured ? '#bbf7d0' : regCheckColor;
|
||||
const btnBg = plan.isFeatured ? '#ffffff' : regBtnBg;
|
||||
const btnColor = plan.isFeatured ? featuredBg : regBtnColor;
|
||||
const textColor = plan.isFeatured ? '#ffffff' : '#18181b';
|
||||
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b';
|
||||
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563';
|
||||
const checkColor = plan.isFeatured ? '#bbf7d0' : '#10b981';
|
||||
const btnBg = plan.isFeatured ? '#ffffff' : featuredBg;
|
||||
const btnColor = plan.isFeatured ? featuredBg : '#ffffff';
|
||||
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);';
|
||||
|
||||
|
||||
@@ -80,14 +80,3 @@ describe('Tabs.toHtml deterministic + unique ids (thread node id, resolves id-co
|
||||
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;
|
||||
contentBg?: string;
|
||||
anchorId?: string;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultTabs: TabItem[] = [
|
||||
@@ -119,11 +114,6 @@ Tabs.craft = {
|
||||
inactiveTabColor: '#64748b',
|
||||
contentBg: '#ffffff',
|
||||
anchorId: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
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"');
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
starColor?: string;
|
||||
anchorId?: string;
|
||||
animation?: string;
|
||||
animationDelay?: string;
|
||||
hideOnDesktop?: boolean;
|
||||
hideOnTablet?: boolean;
|
||||
hideOnMobile?: boolean;
|
||||
}
|
||||
|
||||
const defaultTestimonials: Testimonial[] = [
|
||||
@@ -136,11 +131,6 @@ Testimonials.craft = {
|
||||
cardBg: '#f8fafc',
|
||||
starColor: '#f59e0b',
|
||||
anchorId: '',
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
hideOnDesktop: false,
|
||||
hideOnTablet: false,
|
||||
hideOnMobile: false,
|
||||
},
|
||||
rules: {
|
||||
canDrag: () => true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
TEXT_COLORS,
|
||||
BG_COLORS,
|
||||
@@ -17,12 +17,85 @@ import {
|
||||
useNodeProp,
|
||||
} from './shared';
|
||||
import { ArrayItemFieldsEditor } from './ArrayItemFields';
|
||||
import { Modal } from '../../../ui/Modal';
|
||||
import { CodeEditor } from '../../../ui/CodeEditor';
|
||||
|
||||
/* ---------- "Edit HTML" modal for the HtmlBlock `code` prop ----------
|
||||
`code` is raw HTML (potentially many lines, embedded <style>/<script>),
|
||||
so it gets a dedicated syntax-highlighted CodeEditor in a modal instead
|
||||
of falling into the generic single-line/textarea string-prop rendering
|
||||
below (see GenericPropsEditor's SKIP of the `code` key). */
|
||||
const HtmlCodeField: React.FC<{ value: string; onChange: (v: string) => void }> = ({ value, onChange }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<CollapsibleSection title="HTML Code">
|
||||
<div style={sectionGap}>
|
||||
<button
|
||||
onClick={() => setOpen(true)}
|
||||
style={{
|
||||
width: '100%', padding: '8px 12px', fontSize: 12, fontWeight: 600,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6,
|
||||
background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46',
|
||||
borderRadius: 6, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
<i className="fa fa-code" /> Edit HTML
|
||||
</button>
|
||||
</div>
|
||||
<Modal open={open} onClose={() => setOpen(false)} width="min(720px, 90vw)">
|
||||
<div
|
||||
style={{
|
||||
background: 'var(--color-bg-surface)',
|
||||
border: '1px solid var(--color-border)',
|
||||
borderRadius: 12,
|
||||
boxShadow: '0 20px 60px rgba(0,0,0,0.5)',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
||||
padding: '14px 16px', borderBottom: '1px solid var(--color-border)',
|
||||
}}>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--color-text)' }}>Edit HTML</div>
|
||||
<button
|
||||
onClick={() => setOpen(false)}
|
||||
style={{
|
||||
width: 28, height: 28, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
background: 'none', border: '1px solid var(--color-border)', borderRadius: 6,
|
||||
color: 'var(--color-text-muted)', cursor: 'pointer', fontSize: 13,
|
||||
}}
|
||||
>
|
||||
<i className="fa fa-times" />
|
||||
</button>
|
||||
</div>
|
||||
<div style={{ padding: 16 }}>
|
||||
<CodeEditor value={value} onChange={onChange} language="html" height={420} />
|
||||
</div>
|
||||
<div style={{ padding: '10px 16px', borderTop: '1px solid var(--color-border)', display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<button
|
||||
onClick={() => setOpen(false)}
|
||||
style={{
|
||||
padding: '7px 20px', fontSize: 13, fontWeight: 600,
|
||||
background: 'var(--color-accent)', color: '#fff', border: 'none', borderRadius: 6, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</CollapsibleSection>
|
||||
);
|
||||
};
|
||||
|
||||
/* ---------- SMART GENERIC PROPS EDITOR (Fallback) ---------- */
|
||||
export const GenericPropsEditor: React.FC<{ selectedId: string; nodeProps: Record<string, any>; typeName: string }> = ({
|
||||
selectedId, nodeProps, typeName,
|
||||
}) => {
|
||||
const SKIP_PROPS = new Set(['style', 'children', 'cssId', 'cssClass']);
|
||||
const SKIP_PROPS = new Set(['style', 'children', 'cssId', 'cssClass', 'code']);
|
||||
|
||||
const { setProp: setPropValue, setPropStyle: setStyleValue } = useNodeProp(selectedId);
|
||||
|
||||
@@ -35,9 +108,15 @@ export const GenericPropsEditor: React.FC<{ selectedId: string; nodeProps: Recor
|
||||
const arrayProps = allProps.filter(([_, val]) => Array.isArray(val));
|
||||
|
||||
const style = nodeProps.style || {};
|
||||
const hasCodeProp = typeof nodeProps.code === 'string';
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Raw HTML (HtmlBlock's `code` prop) -- dedicated CodeEditor modal */}
|
||||
{hasCodeProp && (
|
||||
<HtmlCodeField value={nodeProps.code} onChange={(v) => setPropValue('code', v)} />
|
||||
)}
|
||||
|
||||
{/* String props */}
|
||||
{stringProps.length > 0 && (
|
||||
<CollapsibleSection title="Properties">
|
||||
|
||||
@@ -1,38 +1,16 @@
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { useEditor } from '@craftjs/core';
|
||||
import { SHADOW_PRESETS } from '../../../constants/presets';
|
||||
import {
|
||||
StylePanelProps,
|
||||
CollapsibleSection,
|
||||
ColorPickerField,
|
||||
SectionLabel,
|
||||
PresetButtonGrid,
|
||||
labelStyle,
|
||||
inputStyle,
|
||||
smallInputStyle,
|
||||
btnActiveStyle,
|
||||
sectionGap,
|
||||
useNodeProp,
|
||||
SpacingControl,
|
||||
BorderControl,
|
||||
BorderValue,
|
||||
buildBorderShorthand,
|
||||
AnimationControl,
|
||||
VisibilityControl,
|
||||
} 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 = [
|
||||
{ label: '✓', value: 'check' },
|
||||
{ label: '●', value: 'dot' },
|
||||
@@ -48,12 +26,10 @@ const bulletChar: Record<string, string> = {
|
||||
|
||||
export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||
const { actions } = useEditor();
|
||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||
const [expandedPlan, setExpandedPlan] = useState<number>(0);
|
||||
|
||||
const plans: any[] = Array.isArray(nodeProps.plans) ? nodeProps.plans : [];
|
||||
const currentBullet = nodeProps.bulletType || 'check';
|
||||
const style = nodeProps.style || {};
|
||||
|
||||
const updatePlan = useCallback((planIndex: number, field: string, value: any) => {
|
||||
actions.setProp(selectedId, (props: any) => {
|
||||
@@ -228,79 +204,6 @@ export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeP
|
||||
{/* Colors */}
|
||||
<CollapsibleSection title="Colors" defaultOpen={false}>
|
||||
<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>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
BG_COLORS,
|
||||
SPACING_PRESETS,
|
||||
RADIUS_PRESETS,
|
||||
SHADOW_PRESETS,
|
||||
} from '../../../constants/presets';
|
||||
import {
|
||||
StylePanelProps,
|
||||
@@ -16,31 +15,10 @@ import {
|
||||
inputStyle,
|
||||
sectionGap,
|
||||
useNodeProp,
|
||||
SpacingControl,
|
||||
BorderControl,
|
||||
BorderValue,
|
||||
buildBorderShorthand,
|
||||
AnimationControl,
|
||||
VisibilityControl,
|
||||
} from './shared';
|
||||
import { FeaturesEditor } from './FeaturesEditor';
|
||||
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.) ---------- */
|
||||
export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }> = ({ selectedId, nodeProps, typeName }) => {
|
||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||
@@ -48,12 +26,7 @@ export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }>
|
||||
const style = nodeProps.style || {};
|
||||
|
||||
// Find all string/number/boolean props
|
||||
const SKIP_PROPS = new Set([
|
||||
'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 SKIP_PROPS = new Set(['style', 'children', 'cssId', 'cssClass']);
|
||||
const scalarProps = Object.entries(nodeProps).filter(
|
||||
([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)} />
|
||||
</div>
|
||||
</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 {
|
||||
BG_COLORS,
|
||||
SPACING_PRESETS,
|
||||
SHADOW_PRESETS,
|
||||
} from '../../../constants/presets';
|
||||
import {
|
||||
StylePanelProps,
|
||||
@@ -18,33 +17,8 @@ import {
|
||||
btnActiveStyle,
|
||||
sectionGap,
|
||||
useNodeProp,
|
||||
SpacingControl,
|
||||
BorderControl,
|
||||
BorderValue,
|
||||
buildBorderShorthand,
|
||||
AnimationControl,
|
||||
VisibilityControl,
|
||||
} 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 ---------- */
|
||||
export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||
const { actions } = useEditor();
|
||||
@@ -137,72 +111,6 @@ export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePr
|
||||
</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 */}
|
||||
{nodeProps.iconColor !== undefined && (
|
||||
<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)} />
|
||||
</div>
|
||||
</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,85 @@
|
||||
import { describe, test, expect, vi, afterEach } from 'vitest';
|
||||
import React from 'react';
|
||||
import { createRoot, Root } from 'react-dom/client';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { HeadCodeModal } from './HeadCodeModal';
|
||||
import { SiteDesignProvider, useSiteDesign } from '../../state/SiteDesignContext';
|
||||
|
||||
/* ---------- DOM test harness -- same react-dom/client + `act` pattern used
|
||||
throughout src/ui/*.test.tsx (no @testing-library/react in this repo). ---------- */
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (container) {
|
||||
act(() => { root.unmount(); });
|
||||
container.remove();
|
||||
}
|
||||
document.body.style.overflow = '';
|
||||
});
|
||||
|
||||
// Exposes the current headCode so assertions can read it back after a
|
||||
// simulated edit -- CodeEditor writes through `updateDesign`, this just
|
||||
// surfaces the result.
|
||||
function Harness({ onReady }: { onReady: (headCode: string) => void }) {
|
||||
const { design } = useSiteDesign();
|
||||
onReady(design.headCode);
|
||||
return null;
|
||||
}
|
||||
|
||||
describe('HeadCodeModal', () => {
|
||||
// HeadCodeModal portals its content to document.body (see the comment in
|
||||
// HeadCodeModal.tsx), so the rendered DOM lives outside `container` --
|
||||
// query document.body instead.
|
||||
|
||||
test('renders the CodeEditor (fallback textarea path) seeded with the current headCode', () => {
|
||||
render(
|
||||
<SiteDesignProvider>
|
||||
<HeadCodeModal open onClose={vi.fn()} />
|
||||
</SiteDesignProvider>,
|
||||
);
|
||||
// CodeMirror loads via async dynamic import (see CodeEditor.test.tsx);
|
||||
// synchronously after mount the fallback textarea is what's live.
|
||||
const textarea = document.body.querySelector<HTMLTextAreaElement>('[data-testid="code-editor-fallback"]');
|
||||
expect(textarea).not.toBeNull();
|
||||
expect(textarea!.value).toBe('');
|
||||
expect(textarea!.dataset.language).toBe('html');
|
||||
});
|
||||
|
||||
test('typing in the editor writes through to SiteDesignContext.headCode', () => {
|
||||
let latestHeadCode = '';
|
||||
render(
|
||||
<SiteDesignProvider>
|
||||
<HeadCodeModal open onClose={vi.fn()} />
|
||||
<Harness onReady={(v) => { latestHeadCode = v; }} />
|
||||
</SiteDesignProvider>,
|
||||
);
|
||||
|
||||
const textarea = document.body.querySelector<HTMLTextAreaElement>('[data-testid="code-editor-fallback"]')!;
|
||||
act(() => {
|
||||
const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value')!.set!;
|
||||
setter.call(textarea, '<meta name="x" content="y">');
|
||||
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
|
||||
expect(latestHeadCode).toBe('<meta name="x" content="y">');
|
||||
});
|
||||
|
||||
test('does not render when closed', () => {
|
||||
render(
|
||||
<SiteDesignProvider>
|
||||
<HeadCodeModal open={false} onClose={vi.fn()} />
|
||||
</SiteDesignProvider>,
|
||||
);
|
||||
expect(document.body.querySelector('[data-testid="code-editor-fallback"]')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useSiteDesign } from '../../state/SiteDesignContext';
|
||||
import { Modal } from '../../ui/Modal';
|
||||
import { CodeEditor } from '../../ui/CodeEditor';
|
||||
|
||||
interface HeadCodeModalProps {
|
||||
open: boolean;
|
||||
@@ -55,28 +56,16 @@ export const HeadCodeModal: React.FC<HeadCodeModalProps> = ({ open, onClose }) =
|
||||
Code added here will be injected into the <code style={{ background: 'rgba(255,255,255,0.08)', padding: '1px 4px', borderRadius: 3, fontSize: 11 }}><head></code> of every page on your site. Use it for analytics, custom fonts, or global CSS.
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
<div style={{ flex: 1, minHeight: 300 }}>
|
||||
<CodeEditor
|
||||
value={design.headCode || ''}
|
||||
onChange={(e) => updateDesign({ headCode: e.target.value })}
|
||||
onChange={(code) => updateDesign({ headCode: code })}
|
||||
language="html"
|
||||
height="100%"
|
||||
placeholder={"<!-- Google Analytics -->\n<script async src=\"https://...\"></script>\n\n<!-- Custom Fonts -->\n<link href=\"https://fonts.googleapis.com/...\" rel=\"stylesheet\">\n\n<style>\n /* Global CSS overrides */\n body { }\n</style>"}
|
||||
style={{
|
||||
flex: 1,
|
||||
minHeight: 300,
|
||||
padding: 14,
|
||||
background: '#0d0d0f',
|
||||
color: '#e4e4e7',
|
||||
border: '1px solid #3f3f46',
|
||||
borderRadius: 8,
|
||||
fontFamily: 'Source Code Pro, Consolas, monospace',
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
resize: 'vertical',
|
||||
outline: 'none',
|
||||
tabSize: 2,
|
||||
}}
|
||||
spellCheck={false}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div style={{
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { describe, test, expect, vi, afterEach } from 'vitest';
|
||||
import React from 'react';
|
||||
import { createRoot, Root } from 'react-dom/client';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { CodeEditor } from './CodeEditor';
|
||||
|
||||
/* ---------- DOM test harness (no @testing-library/react in this repo; see
|
||||
src/ui/AssetPicker.test.tsx / src/ui/Modal.test.tsx for the same
|
||||
react-dom/client + react-dom/test-utils `act` pattern). ----------
|
||||
|
||||
CodeMirror is loaded via dynamic import() (see CodeEditor.tsx), which is
|
||||
always async -- even for an already-resolved/cached module, `import()`
|
||||
only settles on a later microtask. That means immediately after the
|
||||
initial synchronous `act(() => root.render(...))` below, the component is
|
||||
still in its 'loading' state and renders the <textarea> fallback. These
|
||||
tests deliberately assert against that first-tick DOM (never awaiting
|
||||
the CodeMirror promise), so they exercise exactly the fallback path a
|
||||
real headless/offline environment would fall back to, deterministically
|
||||
and without needing to mock @codemirror/*. */
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (container) {
|
||||
act(() => { root.unmount(); });
|
||||
container.remove();
|
||||
}
|
||||
});
|
||||
|
||||
function fallbackTextarea(): HTMLTextAreaElement {
|
||||
const el = container.querySelector<HTMLTextAreaElement>('[data-testid="code-editor-fallback"]');
|
||||
if (!el) throw new Error('fallback textarea not found');
|
||||
return el;
|
||||
}
|
||||
|
||||
describe('CodeEditor', () => {
|
||||
test('shows the textarea fallback immediately (CodeMirror loads async)', () => {
|
||||
render(<CodeEditor value="<p>hi</p>" onChange={vi.fn()} />);
|
||||
const textarea = fallbackTextarea();
|
||||
expect(textarea.value).toBe('<p>hi</p>');
|
||||
});
|
||||
|
||||
test('the CodeMirror mount root is hidden while the fallback is showing', () => {
|
||||
render(<CodeEditor value="" onChange={vi.fn()} />);
|
||||
const cmRoot = container.querySelector<HTMLDivElement>('[data-testid="code-editor-cm-root"]');
|
||||
expect(cmRoot?.style.display).toBe('none');
|
||||
});
|
||||
|
||||
test('onChange fires with the new value when typing in the fallback textarea', () => {
|
||||
const onChange = vi.fn();
|
||||
render(<CodeEditor value="<p>hi</p>" onChange={onChange} />);
|
||||
const textarea = fallbackTextarea();
|
||||
act(() => {
|
||||
const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value')!.set!;
|
||||
setter.call(textarea, '<p>updated</p>');
|
||||
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
expect(onChange).toHaveBeenCalledWith('<p>updated</p>');
|
||||
});
|
||||
|
||||
test('accepts a language prop without throwing (html/css/javascript/auto)', () => {
|
||||
for (const language of ['html', 'css', 'javascript', 'auto'] as const) {
|
||||
expect(() => render(<CodeEditor value="" onChange={vi.fn()} language={language} />)).not.toThrow();
|
||||
const textarea = fallbackTextarea();
|
||||
expect(textarea.dataset.language).toBe(language);
|
||||
act(() => { root.unmount(); });
|
||||
container.remove();
|
||||
}
|
||||
});
|
||||
|
||||
test('defaults to html language when none is passed', () => {
|
||||
render(<CodeEditor value="" onChange={vi.fn()} />);
|
||||
expect(fallbackTextarea().dataset.language).toBe('html');
|
||||
});
|
||||
|
||||
test('respects a custom height', () => {
|
||||
render(<CodeEditor value="" onChange={vi.fn()} height={480} />);
|
||||
expect((container.firstElementChild as HTMLElement).style.height).toBe('480px');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,257 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import type { EditorView as EditorViewType } from '@codemirror/view';
|
||||
|
||||
export type CodeEditorLanguage = 'html' | 'css' | 'javascript' | 'auto';
|
||||
|
||||
export interface CodeEditorProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
/** 'auto' behaves like 'html' -- the HTML language mode already highlights
|
||||
* embedded <script>/<style> blocks, which covers the common "auto" case
|
||||
* of mixed markup. */
|
||||
language?: CodeEditorLanguage;
|
||||
height?: number | string;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
Lazy-loaded CodeMirror 6.
|
||||
|
||||
All @codemirror/* packages are pulled in via dynamic import() so they
|
||||
land in their own chunk(s) (see vite.config.ts chunkFileNames) instead of
|
||||
bloating the main editor.js bundle -- most sessions never open a code
|
||||
editor. The module set is fetched once (module-level promise, shared
|
||||
across every CodeEditor instance on the page) and cached forever.
|
||||
|
||||
While the import is in flight -- or if it ever fails (offline, CDN
|
||||
hiccup, an environment where CodeMirror can't mount e.g. some headless
|
||||
test runners) -- callers get a plain <textarea> so editing never breaks,
|
||||
just loses syntax highlighting/autocomplete.
|
||||
---------------------------------------------------------------- */
|
||||
|
||||
interface CmModules {
|
||||
EditorState: typeof import('@codemirror/state').EditorState;
|
||||
EditorView: typeof import('@codemirror/view').EditorView;
|
||||
keymap: typeof import('@codemirror/view').keymap;
|
||||
lineNumbers: typeof import('@codemirror/view').lineNumbers;
|
||||
highlightActiveLine: typeof import('@codemirror/view').highlightActiveLine;
|
||||
highlightActiveLineGutter: typeof import('@codemirror/view').highlightActiveLineGutter;
|
||||
drawSelection: typeof import('@codemirror/view').drawSelection;
|
||||
defaultKeymap: typeof import('@codemirror/commands').defaultKeymap;
|
||||
history: typeof import('@codemirror/commands').history;
|
||||
historyKeymap: typeof import('@codemirror/commands').historyKeymap;
|
||||
indentWithTab: typeof import('@codemirror/commands').indentWithTab;
|
||||
syntaxHighlighting: typeof import('@codemirror/language').syntaxHighlighting;
|
||||
defaultHighlightStyle: typeof import('@codemirror/language').defaultHighlightStyle;
|
||||
bracketMatching: typeof import('@codemirror/language').bracketMatching;
|
||||
indentOnInput: typeof import('@codemirror/language').indentOnInput;
|
||||
foldGutter: typeof import('@codemirror/language').foldGutter;
|
||||
autocompletion: typeof import('@codemirror/autocomplete').autocompletion;
|
||||
completionKeymap: typeof import('@codemirror/autocomplete').completionKeymap;
|
||||
closeBrackets: typeof import('@codemirror/autocomplete').closeBrackets;
|
||||
closeBracketsKeymap: typeof import('@codemirror/autocomplete').closeBracketsKeymap;
|
||||
html: typeof import('@codemirror/lang-html').html;
|
||||
css: typeof import('@codemirror/lang-css').css;
|
||||
javascript: typeof import('@codemirror/lang-javascript').javascript;
|
||||
oneDark: typeof import('@codemirror/theme-one-dark').oneDark;
|
||||
}
|
||||
|
||||
let cmModulesPromise: Promise<CmModules> | null = null;
|
||||
|
||||
function loadCodeMirror(): Promise<CmModules> {
|
||||
if (!cmModulesPromise) {
|
||||
cmModulesPromise = Promise.all([
|
||||
import('@codemirror/state'),
|
||||
import('@codemirror/view'),
|
||||
import('@codemirror/commands'),
|
||||
import('@codemirror/language'),
|
||||
import('@codemirror/autocomplete'),
|
||||
import('@codemirror/lang-html'),
|
||||
import('@codemirror/lang-css'),
|
||||
import('@codemirror/lang-javascript'),
|
||||
import('@codemirror/theme-one-dark'),
|
||||
]).then(([state, view, commands, language, autocomplete, langHtml, langCss, langJs, theme]) => ({
|
||||
EditorState: state.EditorState,
|
||||
EditorView: view.EditorView,
|
||||
keymap: view.keymap,
|
||||
lineNumbers: view.lineNumbers,
|
||||
highlightActiveLine: view.highlightActiveLine,
|
||||
highlightActiveLineGutter: view.highlightActiveLineGutter,
|
||||
drawSelection: view.drawSelection,
|
||||
defaultKeymap: commands.defaultKeymap,
|
||||
history: commands.history,
|
||||
historyKeymap: commands.historyKeymap,
|
||||
indentWithTab: commands.indentWithTab,
|
||||
syntaxHighlighting: language.syntaxHighlighting,
|
||||
defaultHighlightStyle: language.defaultHighlightStyle,
|
||||
bracketMatching: language.bracketMatching,
|
||||
indentOnInput: language.indentOnInput,
|
||||
foldGutter: language.foldGutter,
|
||||
autocompletion: autocomplete.autocompletion,
|
||||
completionKeymap: autocomplete.completionKeymap,
|
||||
closeBrackets: autocomplete.closeBrackets,
|
||||
closeBracketsKeymap: autocomplete.closeBracketsKeymap,
|
||||
html: langHtml.html,
|
||||
css: langCss.css,
|
||||
javascript: langJs.javascript,
|
||||
oneDark: theme.oneDark,
|
||||
}));
|
||||
}
|
||||
return cmModulesPromise;
|
||||
}
|
||||
|
||||
function languageExtension(mods: CmModules, language: CodeEditorLanguage) {
|
||||
switch (language) {
|
||||
case 'css':
|
||||
return mods.css();
|
||||
case 'javascript':
|
||||
return mods.javascript();
|
||||
case 'html':
|
||||
case 'auto':
|
||||
default:
|
||||
// lang-html already highlights + completes embedded <script>/<style>
|
||||
// blocks as JS/CSS, which is exactly what "auto" wants for mixed
|
||||
// HTML snippets (head code, HTML blocks).
|
||||
return mods.html({ autoCloseTags: true });
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackStyle: React.CSSProperties = {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
padding: 14,
|
||||
background: '#0d0d0f',
|
||||
color: '#e4e4e7',
|
||||
border: '1px solid #3f3f46',
|
||||
borderRadius: 8,
|
||||
fontFamily: 'Source Code Pro, Consolas, monospace',
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
resize: 'none',
|
||||
outline: 'none',
|
||||
tabSize: 2,
|
||||
boxSizing: 'border-box',
|
||||
};
|
||||
|
||||
export const CodeEditor: React.FC<CodeEditorProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
language = 'html',
|
||||
height = 320,
|
||||
placeholder,
|
||||
}) => {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const viewRef = useRef<EditorViewType | null>(null);
|
||||
const onChangeRef = useRef(onChange);
|
||||
onChangeRef.current = onChange;
|
||||
// Tracks the last value this component itself emitted, so the
|
||||
// value-sync effect below doesn't stomp on in-progress typing when the
|
||||
// parent re-renders with the exact same string it was just handed.
|
||||
const lastEmittedRef = useRef(value);
|
||||
const [status, setStatus] = useState<'loading' | 'ready' | 'error'>('loading');
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setStatus('loading');
|
||||
|
||||
loadCodeMirror()
|
||||
.then((mods) => {
|
||||
if (cancelled || !containerRef.current) return;
|
||||
const updateListener = mods.EditorView.updateListener.of((update) => {
|
||||
if (update.docChanged) {
|
||||
const next = update.state.doc.toString();
|
||||
lastEmittedRef.current = next;
|
||||
onChangeRef.current(next);
|
||||
}
|
||||
});
|
||||
const state = mods.EditorState.create({
|
||||
doc: value,
|
||||
extensions: [
|
||||
mods.lineNumbers(),
|
||||
mods.highlightActiveLineGutter(),
|
||||
mods.highlightActiveLine(),
|
||||
mods.history(),
|
||||
mods.foldGutter(),
|
||||
mods.drawSelection(),
|
||||
mods.indentOnInput(),
|
||||
mods.syntaxHighlighting(mods.defaultHighlightStyle, { fallback: true }),
|
||||
mods.bracketMatching(),
|
||||
mods.closeBrackets(),
|
||||
mods.autocompletion(),
|
||||
mods.keymap.of([
|
||||
...mods.closeBracketsKeymap,
|
||||
...mods.historyKeymap,
|
||||
...mods.completionKeymap,
|
||||
...mods.defaultKeymap,
|
||||
mods.indentWithTab,
|
||||
]),
|
||||
languageExtension(mods, language),
|
||||
mods.oneDark,
|
||||
mods.EditorView.lineWrapping,
|
||||
updateListener,
|
||||
],
|
||||
});
|
||||
const view = new mods.EditorView({ state, parent: containerRef.current });
|
||||
viewRef.current = view;
|
||||
setStatus('ready');
|
||||
})
|
||||
.catch((err) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('CodeEditor: CodeMirror failed to load, falling back to a plain textarea', err);
|
||||
if (!cancelled) setStatus('error');
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
viewRef.current?.destroy();
|
||||
viewRef.current = null;
|
||||
};
|
||||
// Re-mount on language change (language is fixed for HTML/CSS/JS
|
||||
// targets in this app -- it never flips on an already-open editor --
|
||||
// but re-creating cleanly if it ever does is simpler/safer than trying
|
||||
// to reconfigure the LanguageSupport extension in place).
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [language]);
|
||||
|
||||
// Keep the live CodeMirror doc in sync if `value` changes from outside
|
||||
// (e.g. the modal is reused for a different field) without clobbering
|
||||
// the cursor position/selection on every keystroke-driven re-render.
|
||||
useEffect(() => {
|
||||
const view = viewRef.current;
|
||||
if (!view || status !== 'ready') return;
|
||||
if (value === lastEmittedRef.current) return;
|
||||
const current = view.state.doc.toString();
|
||||
if (current === value) return;
|
||||
view.dispatch({ changes: { from: 0, to: current.length, insert: value } });
|
||||
lastEmittedRef.current = value;
|
||||
}, [value, status]);
|
||||
|
||||
const showFallback = status !== 'ready';
|
||||
|
||||
return (
|
||||
<div style={{ position: 'relative', height, minHeight: height }}>
|
||||
<div
|
||||
ref={containerRef}
|
||||
data-testid="code-editor-cm-root"
|
||||
style={{
|
||||
height: '100%',
|
||||
overflow: 'auto',
|
||||
borderRadius: 8,
|
||||
border: '1px solid #3f3f46',
|
||||
display: showFallback ? 'none' : 'block',
|
||||
}}
|
||||
/>
|
||||
{showFallback && (
|
||||
<textarea
|
||||
data-testid="code-editor-fallback"
|
||||
data-language={language}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={status === 'loading' ? (placeholder || 'Loading editor…') : placeholder}
|
||||
spellCheck={false}
|
||||
style={fallbackStyle}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user