Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b19ae97af |
@@ -30,3 +30,46 @@ describe('SearchBar.toHtml XSS hardening (placeholder/buttonText/showButton)', (
|
|||||||
expect(html).toMatch(/border-radius:(8px 0 0 8px|8px)/);
|
expect(html).toMatch(/border-radius:(8px 0 0 8px|8px)/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// F2: SearchBar was purely decorative -- no action/method/input name, so
|
||||||
|
// submitting did nothing. It now emits a real GET form.
|
||||||
|
describe('SearchBar.toHtml is a functional GET search form (not decorative)', () => {
|
||||||
|
test('defaults to a GET form action="/" with the query input named "q"', () => {
|
||||||
|
const { html } = toHtml({}, '');
|
||||||
|
expect(html).toMatch(/<form role="search" action="\/" method="GET"/);
|
||||||
|
expect(html).toContain('<input type="search" name="q"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a configured action (real search-results page) is used verbatim', () => {
|
||||||
|
const { html } = toHtml({ action: '/search' }, '');
|
||||||
|
expect(html).toContain('action="/search"');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a javascript: action is blocked via safeUrl and falls back to "/"', () => {
|
||||||
|
const { html } = toHtml({ action: 'javascript:alert(1)' }, '');
|
||||||
|
expect(html).toContain('action="/"');
|
||||||
|
expect(html).not.toContain('javascript:');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an empty/whitespace action falls back to "/"', () => {
|
||||||
|
const { html } = toHtml({ action: ' ' }, '');
|
||||||
|
expect(html).toContain('action="/"');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SearchBar.toHtml box-model style passthrough', () => {
|
||||||
|
test('margin/border/box-shadow/opacity flow through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ style: { marginBottom: '14px', border: '1px solid #aaa', boxShadow: '0 1px 4px rgba(0,0,0,.1)', opacity: '0.9' } }, '');
|
||||||
|
expect(html).toContain('margin-bottom:14px');
|
||||||
|
expect(html).toContain('border:1px solid #aaa');
|
||||||
|
expect(html).toContain('opacity:0.9');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SearchBar.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(SearchBar.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
import React, { CSSProperties } from 'react';
|
import React, { CSSProperties } from 'react';
|
||||||
import { useNode, UserComponent } from '@craftjs/core';
|
import { useNode, UserComponent } from '@craftjs/core';
|
||||||
import { cssPropsToString } from '../../utils/style-helpers';
|
import { cssPropsToString } from '../../utils/style-helpers';
|
||||||
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
import { escapeHtml, escapeAttr, safeUrl } from '../../utils/escape';
|
||||||
|
|
||||||
interface SearchBarProps {
|
interface SearchBarProps {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
buttonText?: string;
|
buttonText?: string;
|
||||||
showButton?: boolean;
|
showButton?: boolean;
|
||||||
|
/** Where the search GET request is submitted -- a real search-results page
|
||||||
|
* if the site has one, or '/' (site root) by default. The query is sent
|
||||||
|
* as `?q=...`, the conventional param name search-results pages look for. */
|
||||||
|
action?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SearchBar: UserComponent<SearchBarProps> = ({
|
export const SearchBar: UserComponent<SearchBarProps> = ({
|
||||||
placeholder = 'Search...',
|
placeholder = 'Search...',
|
||||||
buttonText = 'Search',
|
buttonText = 'Search',
|
||||||
showButton = true,
|
showButton = true,
|
||||||
|
action = '/',
|
||||||
style = {},
|
style = {},
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
@@ -27,6 +37,8 @@ export const SearchBar: UserComponent<SearchBarProps> = ({
|
|||||||
<form
|
<form
|
||||||
ref={(ref: HTMLFormElement | null): void => { if (ref) connect(drag(ref)); }}
|
ref={(ref: HTMLFormElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||||
role="search"
|
role="search"
|
||||||
|
action={action}
|
||||||
|
method="GET"
|
||||||
onSubmit={(e) => e.preventDefault()}
|
onSubmit={(e) => e.preventDefault()}
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -51,6 +63,7 @@ export const SearchBar: UserComponent<SearchBarProps> = ({
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="search"
|
type="search"
|
||||||
|
name="q"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -101,7 +114,13 @@ SearchBar.craft = {
|
|||||||
placeholder: 'Search...',
|
placeholder: 'Search...',
|
||||||
buttonText: 'Search',
|
buttonText: 'Search',
|
||||||
showButton: true,
|
showButton: true,
|
||||||
|
action: '/',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -117,6 +136,7 @@ SearchBar.craft = {
|
|||||||
placeholder = 'Search...',
|
placeholder = 'Search...',
|
||||||
buttonText = 'Search',
|
buttonText = 'Search',
|
||||||
showButton = true,
|
showButton = true,
|
||||||
|
action = '/',
|
||||||
style = {},
|
style = {},
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
@@ -133,11 +153,19 @@ SearchBar.craft = {
|
|||||||
? `<button type="submit" style="padding:12px 20px;font-size:15px;font-weight:600;font-family:Inter,sans-serif;color:#ffffff;background-color:#3b82f6;border:none;border-radius:0 8px 8px 0;cursor:pointer;white-space:nowrap;display:flex;align-items:center;gap:6px"><i class="fa fa-search" style="font-size:13px" aria-hidden="true"></i>${escapeHtml(buttonText)}</button>`
|
? `<button type="submit" style="padding:12px 20px;font-size:15px;font-weight:600;font-family:Inter,sans-serif;color:#ffffff;background-color:#3b82f6;border:none;border-radius:0 8px 8px 0;cursor:pointer;white-space:nowrap;display:flex;align-items:center;gap:6px"><i class="fa fa-search" style="font-size:13px" aria-hidden="true"></i>${escapeHtml(buttonText)}</button>`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
|
// F2: previously a purely decorative <form> -- no action/method/input
|
||||||
|
// name at all, so submitting did nothing. A real GET to `action` with the
|
||||||
|
// query in the conventional `q` param makes this a functioning search
|
||||||
|
// form on publish (routes to a real search-results page if the site has
|
||||||
|
// one, or reloads '/' with ?q=... by default). `safeUrl` blocks
|
||||||
|
// javascript:/vbscript:/data:text/html breakout via the action attribute.
|
||||||
|
const actionAttr = escapeAttr(safeUrl(action) || '/');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: `<form role="search"${formStyle ? ` style="${formStyle}"` : ''}>
|
html: `<form role="search" action="${actionAttr}" method="GET"${formStyle ? ` style="${formStyle}"` : ''}>
|
||||||
<div style="position:relative;flex:1">
|
<div style="position:relative;flex:1">
|
||||||
<i class="fa fa-search" style="position:absolute;left:14px;top:50%;transform:translateY(-50%);color:#9ca3af;font-size:14px;pointer-events:none" aria-hidden="true"></i>
|
<i class="fa fa-search" style="position:absolute;left:14px;top:50%;transform:translateY(-50%);color:#9ca3af;font-size:14px;pointer-events:none" aria-hidden="true"></i>
|
||||||
<input type="search" placeholder="${escapeAttr(placeholder)}" style="${inputStyleStr}" />
|
<input type="search" name="q" placeholder="${escapeAttr(placeholder)}" style="${inputStyleStr}" />
|
||||||
</div>
|
</div>
|
||||||
${btnHtml}
|
${btnHtml}
|
||||||
</form>`,
|
</form>`,
|
||||||
|
|||||||
@@ -126,3 +126,73 @@ describe('ContactForm.toHtml field type attribute sanitization', () => {
|
|||||||
expect(html).toContain('type="email"');
|
expect(html).toContain('type="email"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// F1: the field editor (FormStylePanel) can now create fields of every type
|
||||||
|
// in sanitizeInputType's allowlist, plus textarea/select. Verify each
|
||||||
|
// renders with the right control, label/for association, and required flag.
|
||||||
|
describe('ContactForm.toHtml renders every configured field type/label/required', () => {
|
||||||
|
const cases: { type: string; tag: string }[] = [
|
||||||
|
{ type: 'text', tag: 'input' },
|
||||||
|
{ type: 'email', tag: 'input' },
|
||||||
|
{ type: 'tel', tag: 'input' },
|
||||||
|
{ type: 'number', tag: 'input' },
|
||||||
|
{ type: 'password', tag: 'input' },
|
||||||
|
{ type: 'url', tag: 'input' },
|
||||||
|
{ type: 'search', tag: 'input' },
|
||||||
|
{ type: 'date', tag: 'input' },
|
||||||
|
{ type: 'checkbox', tag: 'input' },
|
||||||
|
{ type: 'radio', tag: 'input' },
|
||||||
|
];
|
||||||
|
|
||||||
|
test.each(cases)('type=$type renders a sanitized <$tag type="$type"> with label + for/id wiring', ({ type, tag }) => {
|
||||||
|
const fields = [{ type: type as any, label: `Field ${type}`, name: `f_${type}`, placeholder: '', required: true }];
|
||||||
|
const { html } = toHtml({ fields }, '');
|
||||||
|
expect(html).toContain(`<${tag}`);
|
||||||
|
expect(html).toContain(`type="${type}"`);
|
||||||
|
expect(html).toContain(`Field ${type}`);
|
||||||
|
// required renders the input attribute AND the visual asterisk
|
||||||
|
expect(html).toMatch(/ required/);
|
||||||
|
expect(html).toContain('*</span>');
|
||||||
|
const labelFor = html.match(/<label for="([^"]+)"/)![1];
|
||||||
|
expect(html).toContain(`id="${labelFor}"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('type=textarea renders a <textarea>, not an <input>', () => {
|
||||||
|
const fields = [{ type: 'textarea' as const, label: 'Message', name: 'message', placeholder: '', required: false }];
|
||||||
|
const { html } = toHtml({ fields }, '');
|
||||||
|
expect(html).toMatch(/<textarea[^>]*name="message"/);
|
||||||
|
expect(html).not.toMatch(/<input[^>]*name="message"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('type=select renders a <select> with escaped <option> values from field.options', () => {
|
||||||
|
const fields = [{ type: 'select' as const, label: 'Plan', name: 'plan', placeholder: 'Choose one', required: false, options: ['Basic', 'Pro', '"><script>alert(1)</script>'] }];
|
||||||
|
const { html } = toHtml({ fields }, '');
|
||||||
|
expect(html).toMatch(/<select[^>]*name="plan"/);
|
||||||
|
expect(html).toContain('<option value="Basic">Basic</option>');
|
||||||
|
expect(html).toContain('<option value="Pro">Pro</option>');
|
||||||
|
expect(html).not.toContain('<script>alert(1)</script>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a non-required field omits both the required attribute and the asterisk', () => {
|
||||||
|
const fields = [{ type: 'text' as const, label: 'Nickname', name: 'nickname', placeholder: '', required: false }];
|
||||||
|
const { html } = toHtml({ fields }, '');
|
||||||
|
expect(html).not.toMatch(/ required/);
|
||||||
|
expect(html).not.toContain('*</span>');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Box-model / animation / visibility rollout (common enh-batch pattern):
|
||||||
|
// these are top-level props consumed generically by the export's
|
||||||
|
// buildDataAttrs() -- this just confirms the defaults are present on
|
||||||
|
// craft.props so the panel controls render and the props survive save/load.
|
||||||
|
describe('ContactForm.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults for animation, animationDelay, hideOnDesktop/Tablet/Mobile', () => {
|
||||||
|
expect(ContactForm.craft!.props).toMatchObject({
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -4,8 +4,17 @@ import { cssPropsToString } from '../../utils/style-helpers';
|
|||||||
import { relayFormWiring } from '../../utils/form-relay-wiring';
|
import { relayFormWiring } from '../../utils/form-relay-wiring';
|
||||||
import { escapeHtml, escapeAttr, slugId, cssValue, sanitizeInputType } from '../../utils/escape';
|
import { escapeHtml, escapeAttr, slugId, cssValue, sanitizeInputType } from '../../utils/escape';
|
||||||
|
|
||||||
|
// The allowlist enforced at export time lives in `sanitizeInputType`
|
||||||
|
// (utils/escape.ts) -- this union is a superset (it also covers 'textarea'
|
||||||
|
// and 'select', which take their own render branches instead of an
|
||||||
|
// `<input type>`), kept in sync by hand since TS unions can't import a
|
||||||
|
// runtime array.
|
||||||
|
export type ContactFormFieldType =
|
||||||
|
| 'text' | 'email' | 'tel' | 'number' | 'password' | 'url' | 'search' | 'date'
|
||||||
|
| 'checkbox' | 'radio' | 'textarea' | 'select';
|
||||||
|
|
||||||
interface ContactFormField {
|
interface ContactFormField {
|
||||||
type: 'text' | 'email' | 'tel' | 'textarea' | 'select';
|
type: ContactFormFieldType;
|
||||||
label: string;
|
label: string;
|
||||||
name: string;
|
name: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
@@ -25,6 +34,11 @@ interface ContactFormProps {
|
|||||||
inputBorder?: string;
|
inputBorder?: string;
|
||||||
recipientEmail?: string;
|
recipientEmail?: string;
|
||||||
thankYouUrl?: string;
|
thankYouUrl?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultFields: ContactFormField[] = [
|
const defaultFields: ContactFormField[] = [
|
||||||
@@ -157,6 +171,11 @@ ContactForm.craft = {
|
|||||||
inputBorder: '#d1d5db',
|
inputBorder: '#d1d5db',
|
||||||
recipientEmail: '',
|
recipientEmail: '',
|
||||||
thankYouUrl: '',
|
thankYouUrl: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -22,4 +22,19 @@ describe('FormButton.toHtml', () => {
|
|||||||
expect(html).toContain('&');
|
expect(html).toContain('&');
|
||||||
expect(html).toContain('"quoted"');
|
expect(html).toContain('"quoted"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('box-model style (margin/border/box-shadow/opacity) flows through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ text: 'Submit', style: { marginTop: '12px', border: '2px solid #000', boxShadow: '0 2px 4px rgba(0,0,0,.2)', opacity: '0.8' } }, '');
|
||||||
|
expect(html).toContain('margin-top:12px');
|
||||||
|
expect(html).toContain('border:2px solid #000');
|
||||||
|
expect(html).toContain('opacity:0.8');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('FormButton.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(FormButton.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import { escapeHtml } from '../../utils/escape';
|
|||||||
interface FormButtonProps {
|
interface FormButtonProps {
|
||||||
text?: string;
|
text?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FormButton: UserComponent<FormButtonProps> = ({
|
export const FormButton: UserComponent<FormButtonProps> = ({
|
||||||
@@ -58,6 +63,11 @@ FormButton.craft = {
|
|||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
},
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -52,3 +52,20 @@ describe('FormContainer.toHtml method attribute sanitization', () => {
|
|||||||
expect(html).toContain('method="GET"');
|
expect(html).toContain('method="GET"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('FormContainer.toHtml box-model style passthrough', () => {
|
||||||
|
test('margin/border/box-shadow/opacity flow through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ action: '/legacy', style: { marginTop: '20px', border: '3px dashed #ccc', boxShadow: '0 4px 8px rgba(0,0,0,.2)', opacity: '0.95' } }, '');
|
||||||
|
expect(html).toContain('margin-top:20px');
|
||||||
|
expect(html).toContain('border:3px dashed #ccc');
|
||||||
|
expect(html).toContain('opacity:0.95');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('FormContainer.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(FormContainer.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ interface FormContainerProps {
|
|||||||
thankYouUrl?: string;
|
thankYouUrl?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FormContainer: UserComponent<FormContainerProps> = ({
|
export const FormContainer: UserComponent<FormContainerProps> = ({
|
||||||
@@ -59,6 +64,11 @@ FormContainer.craft = {
|
|||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
border: '1px solid #e4e4e7',
|
border: '1px solid #e4e4e7',
|
||||||
},
|
},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -72,3 +72,20 @@ describe('InputField.toHtml type attribute sanitization', () => {
|
|||||||
expect(html).toContain('type="number"');
|
expect(html).toContain('type="number"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('InputField.toHtml box-model style passthrough', () => {
|
||||||
|
test('margin/border/box-shadow/opacity flow through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ label: 'Name', name: 'name', style: { marginBottom: '8px', border: '1px solid #333', boxShadow: '0 1px 2px rgba(0,0,0,.1)', opacity: '0.9' } }, '');
|
||||||
|
expect(html).toContain('margin-bottom:8px');
|
||||||
|
expect(html).toContain('border:1px solid #333');
|
||||||
|
expect(html).toContain('opacity:0.9');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('InputField.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(InputField.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ interface InputFieldProps {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InputField: UserComponent<InputFieldProps> = ({
|
export const InputField: UserComponent<InputFieldProps> = ({
|
||||||
@@ -77,6 +82,11 @@ InputField.craft = {
|
|||||||
placeholder: 'Enter your name',
|
placeholder: 'Enter your name',
|
||||||
required: false,
|
required: false,
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const toHtml = (SubscribeForm as any).toHtml;
|
|||||||
describe('SubscribeForm.toHtml hardcoded attributes stay hardcoded (no raw prop breakout)', () => {
|
describe('SubscribeForm.toHtml hardcoded attributes stay hardcoded (no raw prop breakout)', () => {
|
||||||
test('form method is always POST regardless of any injected props', () => {
|
test('form method is always POST regardless of any injected props', () => {
|
||||||
const { html } = toHtml({ heading: 'Join us', method: 'GET"><script>alert(1)</script>' } as any, '');
|
const { html } = toHtml({ heading: 'Join us', method: 'GET"><script>alert(1)</script>' } as any, '');
|
||||||
expect(html).toContain('<form method="POST"');
|
expect(html).toMatch(/<form action="[^"]*" method="POST"/);
|
||||||
expect(html).not.toContain('<script');
|
expect(html).not.toContain('<script');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,3 +37,45 @@ describe('SubscribeForm.toHtml hardcoded attributes stay hardcoded (no raw prop
|
|||||||
expect(html).toContain('>Go<');
|
expect(html).toContain('>Go<');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// F1: SubscribeForm previously emitted `<form method="POST">` with no action
|
||||||
|
// at all -- a published subscribe form silently did nothing on submit.
|
||||||
|
// Wired through the same relay contract as ContactForm/FormContainer
|
||||||
|
// (utils/form-relay-wiring.ts) so setting a recipient makes it functional.
|
||||||
|
describe('SubscribeForm.toHtml is functional (not a dead POST)', () => {
|
||||||
|
test('without a recipient: still has a real (non-empty) action -- "#" fallback, not a bare method="POST"', () => {
|
||||||
|
const { html } = toHtml({}, '');
|
||||||
|
expect(html).toMatch(/<form action="#" method="POST"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('with recipientEmail: emits the relay marker, placeholder action, and honeypot -- a working submission path', () => {
|
||||||
|
const { html } = toHtml({ recipientEmail: 'news@example.com', thankYouUrl: '/thanks' }, '', 'node-sub1');
|
||||||
|
expect(html).toMatch(/<!--WHP-FORM id="F_[0-9a-z]+" recipient="news@example.com" thankyou="\/thanks"-->/);
|
||||||
|
expect(html).toMatch(/action="__WHP_FORM_ACTION__F_[0-9a-z]+__"/);
|
||||||
|
expect(html).toContain('name="_gotcha"');
|
||||||
|
const mid = html.match(/id="(F_[0-9a-z]+)"/)![1];
|
||||||
|
expect(html).toContain(`__WHP_FORM_ACTION__${mid}__`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the email input keeps its name="email" so the relay receives it', () => {
|
||||||
|
const { html } = toHtml({ recipientEmail: 'news@example.com' }, '', 'node-sub2');
|
||||||
|
expect(html).toContain('name="email"');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SubscribeForm.toHtml box-model style passthrough', () => {
|
||||||
|
test('margin/border/box-shadow/opacity flow through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ style: { marginTop: '16px', border: '1px solid #ddd', boxShadow: '0 2px 6px rgba(0,0,0,.15)', opacity: '0.85' } }, '');
|
||||||
|
expect(html).toContain('margin-top:16px');
|
||||||
|
expect(html).toContain('border:1px solid #ddd');
|
||||||
|
expect(html).toContain('opacity:0.85');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SubscribeForm.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(SubscribeForm.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { CSSProperties } from 'react';
|
import React, { CSSProperties } from 'react';
|
||||||
import { useNode, UserComponent } from '@craftjs/core';
|
import { useNode, UserComponent } from '@craftjs/core';
|
||||||
import { cssPropsToString } from '../../utils/style-helpers';
|
import { cssPropsToString } from '../../utils/style-helpers';
|
||||||
|
import { relayFormWiring } from '../../utils/form-relay-wiring';
|
||||||
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
||||||
|
|
||||||
interface SubscribeFormProps {
|
interface SubscribeFormProps {
|
||||||
@@ -10,6 +11,17 @@ interface SubscribeFormProps {
|
|||||||
buttonColor?: string;
|
buttonColor?: string;
|
||||||
layout?: 'inline' | 'stacked';
|
layout?: 'inline' | 'stacked';
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
/** "Send submissions to" address -- same relay contract as ContactForm/
|
||||||
|
* FormContainer (see utils/form-relay-wiring.ts). Blank = no relay; the
|
||||||
|
* published form then has no working action at all, which is the bug
|
||||||
|
* this prop exists to fix. */
|
||||||
|
recipientEmail?: string;
|
||||||
|
thankYouUrl?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SubscribeForm: UserComponent<SubscribeFormProps> = ({
|
export const SubscribeForm: UserComponent<SubscribeFormProps> = ({
|
||||||
@@ -110,6 +122,13 @@ SubscribeForm.craft = {
|
|||||||
buttonColor: '#3b82f6',
|
buttonColor: '#3b82f6',
|
||||||
layout: 'inline',
|
layout: 'inline',
|
||||||
style: { backgroundColor: '#f8fafc' },
|
style: { backgroundColor: '#f8fafc' },
|
||||||
|
recipientEmail: '',
|
||||||
|
thankYouUrl: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -120,7 +139,7 @@ SubscribeForm.craft = {
|
|||||||
|
|
||||||
/* ---------- HTML export ---------- */
|
/* ---------- HTML export ---------- */
|
||||||
|
|
||||||
(SubscribeForm as any).toHtml = (props: SubscribeFormProps, _childrenHtml: string) => {
|
(SubscribeForm as any).toHtml = (props: SubscribeFormProps, _childrenHtml: string, nodeId?: string) => {
|
||||||
const {
|
const {
|
||||||
heading = 'Subscribe to our newsletter',
|
heading = 'Subscribe to our newsletter',
|
||||||
placeholder = 'Enter your email',
|
placeholder = 'Enter your email',
|
||||||
@@ -166,11 +185,21 @@ SubscribeForm.craft = {
|
|||||||
whiteSpace: 'nowrap',
|
whiteSpace: 'nowrap',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Same relay contract as ContactForm/FormContainer: a recipientEmail wires
|
||||||
|
// the form through the WHP form-sender relay (marker + placeholder action
|
||||||
|
// + honeypot, provisioned/rewritten at publish time). Previously this form
|
||||||
|
// always emitted `<form method="POST">` with NO action at all -- a
|
||||||
|
// published subscribe form silently did nothing on submit. Falling back to
|
||||||
|
// `formAction`-less relay wiring (fallbackAction undefined -> '#') keeps
|
||||||
|
// the old no-recipient case visually identical (action="#") while making
|
||||||
|
// the relay path actually functional once an admin sets an email.
|
||||||
|
const { marker, actionAttr, honeypot } = relayFormWiring(props.recipientEmail, props.thankYouUrl, undefined, nodeId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: `<div${wrapperStyle ? ` style="${wrapperStyle}"` : ''}>
|
html: `${marker}<div${wrapperStyle ? ` style="${wrapperStyle}"` : ''}>
|
||||||
${headingHtml}
|
${headingHtml}
|
||||||
<form method="POST"${formStyle ? ` style="${formStyle}"` : ''}>
|
<form action="${actionAttr}" method="POST"${formStyle ? ` style="${formStyle}"` : ''}>
|
||||||
<input type="email" name="email" placeholder="${escapeAttr(placeholder)}" required style="${inputStyleStr}" />
|
${honeypot ? ` ${honeypot}\n` : ''} <input type="email" name="email" placeholder="${escapeAttr(placeholder)}" required style="${inputStyleStr}" />
|
||||||
<button type="submit"${btnStyle ? ` style="${btnStyle}"` : ''}>${escapeHtml(buttonText)}</button>
|
<button type="submit"${btnStyle ? ` style="${btnStyle}"` : ''}>${escapeHtml(buttonText)}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>`,
|
</div>`,
|
||||||
|
|||||||
@@ -63,3 +63,20 @@ describe('TextareaField.toHtml rows attribute sanitization', () => {
|
|||||||
expect(html).toContain('rows="8"');
|
expect(html).toContain('rows="8"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('TextareaField.toHtml box-model style passthrough', () => {
|
||||||
|
test('margin/border/box-shadow/opacity flow through via the style prop', () => {
|
||||||
|
const { html } = toHtml({ label: 'Message', name: 'message', style: { marginTop: '10px', border: '1px solid #555', boxShadow: '0 1px 3px rgba(0,0,0,.15)', opacity: '0.7' } }, '');
|
||||||
|
expect(html).toContain('margin-top:10px');
|
||||||
|
expect(html).toContain('border:1px solid #555');
|
||||||
|
expect(html).toContain('opacity:0.7');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('TextareaField.craft.props includes animation/visibility defaults', () => {
|
||||||
|
test('has blank/false defaults', () => {
|
||||||
|
expect(TextareaField.craft!.props).toMatchObject({
|
||||||
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ interface TextareaFieldProps {
|
|||||||
rows?: number;
|
rows?: number;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TextareaField: UserComponent<TextareaFieldProps> = ({
|
export const TextareaField: UserComponent<TextareaFieldProps> = ({
|
||||||
@@ -79,6 +84,11 @@ TextareaField.craft = {
|
|||||||
rows: 4,
|
rows: 4,
|
||||||
required: false,
|
required: false,
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -80,56 +80,3 @@ describe('ColumnLayout.toHtml XSS hardening (gap into <style>)', () => {
|
|||||||
expect(html).toMatch(/calc\(50% - 24px\)/);
|
expect(html).toMatch(/calc\(50% - 24px\)/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ColumnLayout.toHtml vertical alignment (align-items on the flex row)', () => {
|
|
||||||
test('style.alignItems flows into the emitted style attribute (aligns uneven columns)', () => {
|
|
||||||
const { html } = toHtml({ columns: 2, split: '50-50', gap: '16px', style: { alignItems: 'center' } }, '<div>A</div><div>B</div>');
|
|
||||||
expect(html).toContain('align-items:center');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ColumnLayout.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(
|
|
||||||
{
|
|
||||||
columns: 2,
|
|
||||||
split: '50-50',
|
|
||||||
gap: '16px',
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'<div>A</div><div>B</div>',
|
|
||||||
);
|
|
||||||
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('ColumnLayout.craft.props exposes the vertical-alignment/box-model/animation/visibility rollout', () => {
|
|
||||||
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
|
||||||
const props = (ColumnLayout 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 alignItems and box-model keys', () => {
|
|
||||||
const style = (ColumnLayout as any).craft.props.style;
|
|
||||||
expect(style).toHaveProperty('alignItems');
|
|
||||||
expect(style).toHaveProperty('marginTop');
|
|
||||||
expect(style).toHaveProperty('paddingTop');
|
|
||||||
expect(style.border).toBe('none');
|
|
||||||
expect(style.boxShadow).toBe('none');
|
|
||||||
expect(style.opacity).toBe('1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ interface ColumnLayoutProps {
|
|||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const splitToWidths: Record<string, string[]> = {
|
const splitToWidths: Record<string, string[]> = {
|
||||||
@@ -107,20 +102,8 @@ ColumnLayout.craft = {
|
|||||||
columns: 2,
|
columns: 2,
|
||||||
split: '50-50',
|
split: '50-50',
|
||||||
gap: '16px',
|
gap: '16px',
|
||||||
style: {
|
style: {},
|
||||||
alignItems: '',
|
|
||||||
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
|
||||||
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
|
||||||
border: 'none',
|
|
||||||
boxShadow: 'none',
|
|
||||||
opacity: '1',
|
|
||||||
},
|
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '0',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -63,88 +63,3 @@ describe('Container.toHtml tag allowlist (adversarial re-review, same class as C
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Container.toHtml vertical alignment (justify-content + min-height)', () => {
|
|
||||||
// Regression lock: Container/Section must NOT unconditionally become a
|
|
||||||
// flex container. Flex-blockifies in-flow children, forcing components
|
|
||||||
// that deliberately render display:inline-block (ButtonLink, Icon) to
|
|
||||||
// stack vertically instead of sitting side-by-side -- a real visual
|
|
||||||
// regression for existing published pages that never touch vertical
|
|
||||||
// alignment.
|
|
||||||
test('does NOT become a flex container when no vertical alignment is set (plain block flow preserved)', () => {
|
|
||||||
const { html } = toHtml({}, 'child');
|
|
||||||
expect(html).not.toContain('display:flex');
|
|
||||||
expect(html).not.toContain('flex-direction');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('does NOT become a flex container from min-height alone (min-height must not itself trigger flex)', () => {
|
|
||||||
const { html } = toHtml({ style: { minHeight: '400px' } }, 'child');
|
|
||||||
expect(html).not.toContain('display:flex');
|
|
||||||
expect(html).not.toContain('flex-direction');
|
|
||||||
expect(html).toContain('min-height:400px');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('becomes a column flex container when style.justifyContent is set (feature still works)', () => {
|
|
||||||
const { html } = toHtml({ style: { justifyContent: 'center' } }, 'child');
|
|
||||||
expect(html).toContain('display:flex');
|
|
||||||
expect(html).toContain('flex-direction:column');
|
|
||||||
expect(html).toContain('justify-content:center');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('style.minHeight flows into the emitted style attribute', () => {
|
|
||||||
const { html } = toHtml({ style: { minHeight: '400px' } }, 'child');
|
|
||||||
expect(html).toContain('min-height:400px');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('justify-content and min-height still flow through in boxed (contentWidth) mode', () => {
|
|
||||||
const { html } = toHtml({ contentWidth: 'boxed', style: { justifyContent: 'flex-end', minHeight: '500px' } }, 'child');
|
|
||||||
expect(html).toContain('display:flex');
|
|
||||||
expect(html).toContain('flex-direction:column');
|
|
||||||
expect(html).toContain('justify-content:flex-end');
|
|
||||||
expect(html).toContain('min-height:500px');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Container.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(
|
|
||||||
{
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'child',
|
|
||||||
);
|
|
||||||
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('Container.craft.props exposes the vertical-alignment/box-model/animation/visibility rollout', () => {
|
|
||||||
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
|
||||||
const props = (Container 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 vertical-alignment and box-model keys', () => {
|
|
||||||
const style = (Container as any).craft.props.style;
|
|
||||||
expect(style).toHaveProperty('justifyContent');
|
|
||||||
expect(style).toHaveProperty('minHeight');
|
|
||||||
expect(style).toHaveProperty('marginTop');
|
|
||||||
expect(style).toHaveProperty('paddingTop');
|
|
||||||
expect(style.border).toBe('none');
|
|
||||||
expect(style.boxShadow).toBe('none');
|
|
||||||
expect(style.opacity).toBe('1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -43,20 +43,6 @@ const flexAlignFromTextAlign = (textAlign: CSSProperties['textAlign']): CSSPrope
|
|||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Container only becomes display:flex/flex-direction:column at its root
|
|
||||||
// (both in the editor render below and in toHtml) when the user has
|
|
||||||
// actually set `style.justifyContent` (the Vertical Alignment control,
|
|
||||||
// paired with `style.minHeight`) -- i.e. the flex conversion is gated on
|
|
||||||
// vertical-align actually being in use, not unconditional. In-flow children
|
|
||||||
// of a flex container get CSS-blockified, which would force components that
|
|
||||||
// deliberately render `display:inline-block` (ButtonLink, Icon) to stack
|
|
||||||
// vertically instead of sitting side-by-side -- a real visual regression for
|
|
||||||
// any container/section that never touches vertical alignment, not a no-op.
|
|
||||||
// So plain block flow (no `display`/`flex-direction` at all) is preserved
|
|
||||||
// unless vertical-align is set. `flexAlignFromTextAlign` above still
|
|
||||||
// supplies its own conditional flex conversion (cross-axis alignItems from
|
|
||||||
// `textAlign`) independently -- unrelated to this gate.
|
|
||||||
|
|
||||||
export const Container: UserComponent<ContainerProps> = ({
|
export const Container: UserComponent<ContainerProps> = ({
|
||||||
style = {},
|
style = {},
|
||||||
tag = 'div',
|
tag = 'div',
|
||||||
@@ -72,12 +58,10 @@ export const Container: UserComponent<ContainerProps> = ({
|
|||||||
const safeTag = sanitizeContainerTag(tag);
|
const safeTag = sanitizeContainerTag(tag);
|
||||||
const needsBoxedWrapper = contentWidth === 'boxed';
|
const needsBoxedWrapper = contentWidth === 'boxed';
|
||||||
const flexStyles = flexAlignFromTextAlign(style.textAlign);
|
const flexStyles = flexAlignFromTextAlign(style.textAlign);
|
||||||
const hasVerticalAlign = !!style.justifyContent;
|
|
||||||
|
|
||||||
const outerStyle: CSSProperties = {
|
const outerStyle: CSSProperties = {
|
||||||
minHeight: '40px',
|
minHeight: '40px',
|
||||||
...style,
|
...style,
|
||||||
...(hasVerticalAlign ? { display: 'flex', flexDirection: 'column' } : {}),
|
|
||||||
...(fullWidth ? { width: '100vw', marginLeft: 'calc(-50vw + 50%)' } : {}),
|
...(fullWidth ? { width: '100vw', marginLeft: 'calc(-50vw + 50%)' } : {}),
|
||||||
...(needsBoxedWrapper ? {} : flexStyles),
|
...(needsBoxedWrapper ? {} : flexStyles),
|
||||||
};
|
};
|
||||||
@@ -109,27 +93,13 @@ export const Container: UserComponent<ContainerProps> = ({
|
|||||||
Container.craft = {
|
Container.craft = {
|
||||||
displayName: 'Container',
|
displayName: 'Container',
|
||||||
props: {
|
props: {
|
||||||
style: {
|
style: { padding: '20px', minHeight: '100px' },
|
||||||
padding: '20px',
|
|
||||||
minHeight: '100px',
|
|
||||||
justifyContent: '',
|
|
||||||
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
|
||||||
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
|
||||||
border: 'none',
|
|
||||||
boxShadow: 'none',
|
|
||||||
opacity: '1',
|
|
||||||
},
|
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
fullWidth: false,
|
fullWidth: false,
|
||||||
contentWidth: 'full',
|
contentWidth: 'full',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
cssId: '',
|
cssId: '',
|
||||||
cssClass: '',
|
cssClass: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '0',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -144,11 +114,9 @@ Container.craft = {
|
|||||||
const tag = sanitizeContainerTag(props.tag);
|
const tag = sanitizeContainerTag(props.tag);
|
||||||
const isBoxed = props.contentWidth === 'boxed';
|
const isBoxed = props.contentWidth === 'boxed';
|
||||||
const flexStyles = flexAlignFromTextAlign(props.style?.textAlign);
|
const flexStyles = flexAlignFromTextAlign(props.style?.textAlign);
|
||||||
const hasVerticalAlign = !!props.style?.justifyContent;
|
|
||||||
|
|
||||||
const outerCss: CSSProperties = {
|
const outerCss: CSSProperties = {
|
||||||
...props.style,
|
...props.style,
|
||||||
...(hasVerticalAlign ? { display: 'flex', flexDirection: 'column' } : {}),
|
|
||||||
...(isBoxed ? {} : flexStyles),
|
...(isBoxed ? {} : flexStyles),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -73,78 +73,3 @@ describe('Section.toHtml shape divider color/height XSS hardening', () => {
|
|||||||
expect(html).not.toContain('<svg');
|
expect(html).not.toContain('<svg');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Section.toHtml vertical alignment (justify-content + min-height)', () => {
|
|
||||||
// Regression lock: same rationale as Container -- see Container.toHtml.test.ts.
|
|
||||||
// Section must not unconditionally become a flex container, or it
|
|
||||||
// blockifies inline-block children (ButtonLink, Icon) that are meant to
|
|
||||||
// sit side-by-side in existing published sections.
|
|
||||||
test('does NOT become a flex container when no vertical alignment is set (plain block flow preserved)', () => {
|
|
||||||
const { html } = toHtml({}, 'child');
|
|
||||||
expect(html).not.toContain('display:flex');
|
|
||||||
expect(html).not.toContain('flex-direction');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('does NOT become a flex container from min-height alone (min-height must not itself trigger flex)', () => {
|
|
||||||
const { html } = toHtml({ style: { minHeight: '600px' } }, 'child');
|
|
||||||
expect(html).not.toContain('display:flex');
|
|
||||||
expect(html).not.toContain('flex-direction');
|
|
||||||
expect(html).toContain('min-height:600px');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('becomes a column flex container when style.justifyContent is set (feature still works)', () => {
|
|
||||||
const { html } = toHtml({ style: { justifyContent: 'center' } }, 'child');
|
|
||||||
expect(html).toContain('display:flex');
|
|
||||||
expect(html).toContain('flex-direction:column');
|
|
||||||
expect(html).toContain('justify-content:center');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('style.minHeight flows into the emitted style attribute', () => {
|
|
||||||
const { html } = toHtml({ style: { minHeight: '600px' } }, 'child');
|
|
||||||
expect(html).toContain('min-height:600px');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Section.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(
|
|
||||||
{
|
|
||||||
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',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'child',
|
|
||||||
);
|
|
||||||
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('Section.craft.props exposes the vertical-alignment/box-model/animation/visibility rollout', () => {
|
|
||||||
test('animation, animationDelay, hideOnDesktop/Tablet/Mobile are present with blank/false defaults', () => {
|
|
||||||
const props = (Section 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 vertical-alignment and box-model keys', () => {
|
|
||||||
const style = (Section as any).craft.props.style;
|
|
||||||
expect(style).toHaveProperty('justifyContent');
|
|
||||||
expect(style).toHaveProperty('minHeight');
|
|
||||||
expect(style).toHaveProperty('marginTop');
|
|
||||||
expect(style).toHaveProperty('paddingTop');
|
|
||||||
expect(style.border).toBe('none');
|
|
||||||
expect(style.boxShadow).toBe('none');
|
|
||||||
expect(style.opacity).toBe('1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ interface SectionProps {
|
|||||||
bottomDividerColor?: string;
|
bottomDividerColor?: string;
|
||||||
bottomDividerHeight?: string;
|
bottomDividerHeight?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
hideOnDesktop?: boolean;
|
|
||||||
hideOnTablet?: boolean;
|
|
||||||
hideOnMobile?: boolean;
|
|
||||||
animation?: string;
|
|
||||||
animationDelay?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- Divider renderer ---------- */
|
/* ---------- Divider renderer ---------- */
|
||||||
@@ -103,13 +98,6 @@ export const Section: UserComponent<SectionProps> = ({
|
|||||||
|
|
||||||
const hasTopDivider = topDivider && topDivider !== 'none';
|
const hasTopDivider = topDivider && topDivider !== 'none';
|
||||||
const hasBottomDivider = bottomDivider && bottomDivider !== 'none';
|
const hasBottomDivider = bottomDivider && bottomDivider !== 'none';
|
||||||
// Section's root only becomes a column flex container when the user has
|
|
||||||
// actually set `style.justifyContent` (Vertical Alignment control, paired
|
|
||||||
// with `style.minHeight`) -- see the matching note in Container.tsx for
|
|
||||||
// why an unconditional conversion is a real regression (blockifies
|
|
||||||
// deliberately inline-block children like ButtonLink/Icon) rather than a
|
|
||||||
// no-op, so plain block flow is preserved unless vertical-align is set.
|
|
||||||
const hasVerticalAlign = !!style.justifyContent;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
@@ -119,7 +107,6 @@ export const Section: UserComponent<SectionProps> = ({
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
position: (hasTopDivider || hasBottomDivider) ? 'relative' : undefined,
|
position: (hasTopDivider || hasBottomDivider) ? 'relative' : undefined,
|
||||||
...style,
|
...style,
|
||||||
...(hasVerticalAlign ? { display: 'flex', flexDirection: 'column' } : {}),
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{hasTopDivider && (
|
{hasTopDivider && (
|
||||||
@@ -156,17 +143,7 @@ export const Section: UserComponent<SectionProps> = ({
|
|||||||
Section.craft = {
|
Section.craft = {
|
||||||
displayName: 'Section',
|
displayName: 'Section',
|
||||||
props: {
|
props: {
|
||||||
style: {
|
style: { padding: '40px 0', backgroundColor: '#ffffff' },
|
||||||
padding: '40px 0',
|
|
||||||
backgroundColor: '#ffffff',
|
|
||||||
minHeight: '',
|
|
||||||
justifyContent: '',
|
|
||||||
marginTop: '', marginRight: '', marginBottom: '', marginLeft: '',
|
|
||||||
paddingTop: '', paddingRight: '', paddingBottom: '', paddingLeft: '',
|
|
||||||
border: 'none',
|
|
||||||
boxShadow: 'none',
|
|
||||||
opacity: '1',
|
|
||||||
},
|
|
||||||
innerMaxWidth: '1200px',
|
innerMaxWidth: '1200px',
|
||||||
topDivider: 'none',
|
topDivider: 'none',
|
||||||
topDividerColor: '#ffffff',
|
topDividerColor: '#ffffff',
|
||||||
@@ -175,11 +152,6 @@ Section.craft = {
|
|||||||
bottomDividerColor: '#ffffff',
|
bottomDividerColor: '#ffffff',
|
||||||
bottomDividerHeight: '50px',
|
bottomDividerHeight: '50px',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
animation: '',
|
|
||||||
animationDelay: '0',
|
|
||||||
hideOnDesktop: false,
|
|
||||||
hideOnTablet: false,
|
|
||||||
hideOnMobile: false,
|
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -227,13 +199,11 @@ function buildDividerHtml(
|
|||||||
(Section as any).toHtml = (props: SectionProps, childrenHtml: string) => {
|
(Section as any).toHtml = (props: SectionProps, childrenHtml: string) => {
|
||||||
const hasTopDivider = props.topDivider && props.topDivider !== 'none';
|
const hasTopDivider = props.topDivider && props.topDivider !== 'none';
|
||||||
const hasBottomDivider = props.bottomDivider && props.bottomDivider !== 'none';
|
const hasBottomDivider = props.bottomDivider && props.bottomDivider !== 'none';
|
||||||
const hasVerticalAlign = !!props.style?.justifyContent;
|
|
||||||
|
|
||||||
const outerStyle = cssPropsToString({
|
const outerStyle = cssPropsToString({
|
||||||
width: '100%',
|
width: '100%',
|
||||||
position: (hasTopDivider || hasBottomDivider) ? 'relative' : undefined,
|
position: (hasTopDivider || hasBottomDivider) ? 'relative' : undefined,
|
||||||
...props.style,
|
...props.style,
|
||||||
...(hasVerticalAlign ? { display: 'flex', flexDirection: 'column' } : {}),
|
|
||||||
});
|
});
|
||||||
const innerStyle = cssPropsToString({
|
const innerStyle = cssPropsToString({
|
||||||
maxWidth: props.innerMaxWidth || '1200px',
|
maxWidth: props.innerMaxWidth || '1200px',
|
||||||
|
|||||||
@@ -10,40 +10,18 @@ import {
|
|||||||
ColorSwatchGrid,
|
ColorSwatchGrid,
|
||||||
GradientSwatchGrid,
|
GradientSwatchGrid,
|
||||||
PresetButtonGrid,
|
PresetButtonGrid,
|
||||||
NumericUnitInput,
|
|
||||||
labelStyle,
|
labelStyle,
|
||||||
inputStyle,
|
inputStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { BoxModelSection, BorderEffectsSection, AnimVisSection } from './containerBoxModel';
|
|
||||||
|
|
||||||
// Vertical Alignment options shown to the user identically regardless of
|
/* ---------- CONTAINER / SECTION ---------- */
|
||||||
// which CSS property they end up mapped to (align-items for the Columns
|
|
||||||
// flex ROW vs. justify-content for Container/Section's flex COLUMN root --
|
|
||||||
// see the per-type branch below).
|
|
||||||
const VERTICAL_ALIGN_OPTIONS: { label: string; value: string }[] = [
|
|
||||||
{ label: 'Top', value: 'flex-start' },
|
|
||||||
{ label: 'Center', value: 'center' },
|
|
||||||
{ label: 'Bottom', value: 'flex-end' },
|
|
||||||
{ label: 'Stretch', value: 'stretch' },
|
|
||||||
];
|
|
||||||
|
|
||||||
/* ---------- CONTAINER / SECTION / COLUMNS ---------- */
|
|
||||||
export const ContainerStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const ContainerStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const style: CSSProperties = nodeProps.style || {};
|
const style: CSSProperties = nodeProps.style || {};
|
||||||
|
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
|
|
||||||
// ColumnLayout only ever carries `columns`/`split` props -- Container and
|
|
||||||
// Section never set them -- so checking either alone distinguishes the
|
|
||||||
// flex-ROW case (align its columns via align-items, aligning uneven
|
|
||||||
// column heights) from the flex-COLUMN case (Container/Section, which
|
|
||||||
// vertically center/position their OWN content via justify-content,
|
|
||||||
// paired with a Min Height control so centering is meaningful).
|
|
||||||
const isColumns = nodeProps.columns !== undefined || nodeProps.split !== undefined;
|
|
||||||
const vAlignKey = isColumns ? 'alignItems' : 'justifyContent';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{nodeProps.cssId !== undefined && (
|
{nodeProps.cssId !== undefined && (
|
||||||
@@ -116,30 +94,6 @@ export const ContainerStylePanel: React.FC<StylePanelProps> = ({ selectedId, nod
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Vertical Alignment</SectionLabel>
|
|
||||||
<PresetButtonGrid
|
|
||||||
presets={VERTICAL_ALIGN_OPTIONS}
|
|
||||||
activeValue={style[vAlignKey] as string}
|
|
||||||
onSelect={(v) => setPropStyle(vAlignKey, v)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{!isColumns && (
|
|
||||||
<div className="guided-section">
|
|
||||||
<SectionLabel>Min Height</SectionLabel>
|
|
||||||
<NumericUnitInput
|
|
||||||
value={(style.minHeight as string) || ''}
|
|
||||||
onChange={(v) => setPropStyle('minHeight', v)}
|
|
||||||
units={['px', 'vh', '%']}
|
|
||||||
placeholder="auto"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Box model + border/effects + animation/visibility rollout */}
|
|
||||||
<BoxModelSection style={style} setPropStyle={setPropStyle} />
|
|
||||||
<BorderEffectsSection style={style} setPropStyle={setPropStyle} />
|
|
||||||
<AnimVisSection nodeProps={nodeProps} setProp={setProp} />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useEditor } from '@craftjs/core';
|
||||||
import {
|
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,
|
||||||
@@ -10,21 +12,152 @@ import {
|
|||||||
ColorSwatchGrid,
|
ColorSwatchGrid,
|
||||||
PresetButtonGrid,
|
PresetButtonGrid,
|
||||||
CollapsibleSection,
|
CollapsibleSection,
|
||||||
|
ArrayPropEditor,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
|
buildBorderShorthand,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
inputStyle,
|
inputStyle,
|
||||||
|
smallInputStyle,
|
||||||
btnActiveStyle,
|
btnActiveStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
|
/* The full sanitizeInputType (utils/escape.ts) allowlist, plus the two
|
||||||
|
fake "types" (textarea/select) that take their own ContactForm render
|
||||||
|
branch instead of an <input type>. Kept as a local list (rather than
|
||||||
|
importing the runtime array from utils/escape.ts) since this is
|
||||||
|
presentation-only -- the actual security boundary is enforced in
|
||||||
|
ContactForm.toHtml via sanitizeInputType, not here. */
|
||||||
|
const CONTACT_FIELD_TYPES = [
|
||||||
|
'text', 'email', 'tel', 'number', 'password', 'url', 'search', 'date',
|
||||||
|
'checkbox', 'radio', 'textarea', 'select',
|
||||||
|
];
|
||||||
|
|
||||||
|
const moveBtnStyle: React.CSSProperties = {
|
||||||
|
flex: 1, padding: '3px 6px', fontSize: 10, background: '#27272a', color: '#a1a1aa',
|
||||||
|
border: '1px solid #3f3f46', borderRadius: 4, cursor: 'pointer',
|
||||||
|
};
|
||||||
|
|
||||||
|
function parseBorderValue(v: unknown): BorderValue {
|
||||||
|
const s = typeof v === 'string' ? v.trim() : '';
|
||||||
|
if (!s || s === 'none') return { width: '', style: 'none', color: '' };
|
||||||
|
const m = s.match(/^(\S+)\s+(\S+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const SPACING_SIDE_KEYS: { side: 'top' | 'right' | 'bottom' | 'left'; suffix: 'Top' | 'Right' | 'Bottom' | 'Left' }[] = [
|
||||||
|
{ side: 'top', suffix: 'Top' },
|
||||||
|
{ side: 'right', suffix: 'Right' },
|
||||||
|
{ side: 'bottom', suffix: 'Bottom' },
|
||||||
|
{ side: 'left', suffix: 'Left' },
|
||||||
|
];
|
||||||
|
|
||||||
/* ---------- FORM ---------- */
|
/* ---------- FORM ---------- */
|
||||||
export const FormStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const FormStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
|
const { actions } = useEditor();
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
|
|
||||||
const style = nodeProps.style || {};
|
const style = nodeProps.style || {};
|
||||||
|
|
||||||
|
const updateField = (index: number, patch: Record<string, any>) => {
|
||||||
|
actions.setProp(selectedId, (props: any) => {
|
||||||
|
const updated = [...(props.fields || [])];
|
||||||
|
updated[index] = { ...updated[index], ...patch };
|
||||||
|
props.fields = updated;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const moveField = (index: number, direction: -1 | 1) => {
|
||||||
|
actions.setProp(selectedId, (props: any) => {
|
||||||
|
const updated = [...(props.fields || [])];
|
||||||
|
const newIndex = index + direction;
|
||||||
|
if (newIndex < 0 || newIndex >= updated.length) return;
|
||||||
|
[updated[index], updated[newIndex]] = [updated[newIndex], updated[index]];
|
||||||
|
props.fields = updated;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{/* ContactForm field editor: add/remove/reorder fields, set each
|
||||||
|
field's label, name, type (full allowlist + textarea/select),
|
||||||
|
options (select only), and required flag. */}
|
||||||
|
{nodeProps.fields !== undefined && Array.isArray(nodeProps.fields) && (
|
||||||
|
<CollapsibleSection title="Fields">
|
||||||
|
<ArrayPropEditor
|
||||||
|
selectedId={selectedId}
|
||||||
|
propKey="fields"
|
||||||
|
items={nodeProps.fields}
|
||||||
|
renderItem={(item: any, index: number) => (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={item.label || ''}
|
||||||
|
onChange={(e) => updateField(index, { label: e.target.value })}
|
||||||
|
placeholder="Label"
|
||||||
|
style={smallInputStyle}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={item.name || ''}
|
||||||
|
onChange={(e) => updateField(index, { name: e.target.value })}
|
||||||
|
placeholder="Field name (e.g. email)"
|
||||||
|
style={smallInputStyle}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={item.placeholder || ''}
|
||||||
|
onChange={(e) => updateField(index, { placeholder: e.target.value })}
|
||||||
|
placeholder="Placeholder"
|
||||||
|
style={smallInputStyle}
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
value={item.type || 'text'}
|
||||||
|
onChange={(e) => updateField(index, { type: e.target.value })}
|
||||||
|
style={{ ...smallInputStyle, cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
{CONTACT_FIELD_TYPES.map((t) => <option key={t} value={t}>{t}</option>)}
|
||||||
|
</select>
|
||||||
|
{item.type === 'select' && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={(item.options || []).join(', ')}
|
||||||
|
onChange={(e) => updateField(index, {
|
||||||
|
options: e.target.value.split(',').map((s: string) => s.trim()).filter(Boolean),
|
||||||
|
})}
|
||||||
|
placeholder="Options (comma-separated)"
|
||||||
|
style={smallInputStyle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: '#e4e4e7', cursor: 'pointer' }}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={!!item.required}
|
||||||
|
onChange={(e) => updateField(index, { required: e.target.checked })}
|
||||||
|
/>
|
||||||
|
Required
|
||||||
|
</label>
|
||||||
|
<div style={{ display: 'flex', gap: 4 }}>
|
||||||
|
<button disabled={index === 0} onClick={() => moveField(index, -1)} style={{ ...moveBtnStyle, opacity: index === 0 ? 0.4 : 1 }} title="Move up">
|
||||||
|
<i className="fa fa-arrow-up" />
|
||||||
|
</button>
|
||||||
|
<button disabled={index === nodeProps.fields.length - 1} onClick={() => moveField(index, 1)} style={{ ...moveBtnStyle, opacity: index === nodeProps.fields.length - 1 ? 0.4 : 1 }} title="Move down">
|
||||||
|
<i className="fa fa-arrow-down" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
emptyItem={{ type: 'text', label: 'New Field', name: 'field', placeholder: '', required: false }}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Contact-form relay: where submissions are emailed. Present on ContactForm
|
{/* Contact-form relay: where submissions are emailed. Present on ContactForm
|
||||||
and FormContainer (both have recipientEmail/thankYouUrl props). */}
|
and FormContainer (both have recipientEmail/thankYouUrl props). */}
|
||||||
{nodeProps.recipientEmail !== undefined && (
|
{nodeProps.recipientEmail !== undefined && (
|
||||||
@@ -43,13 +176,35 @@ export const FormStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProp
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Form action/method */}
|
{/* Form action/method (FormContainer). SearchBar also has an `action`
|
||||||
{nodeProps.action !== undefined && (
|
prop but is distinguished via its unique `showButton` prop -- see
|
||||||
|
the dedicated Search block below -- so it doesn't get this label. */}
|
||||||
|
{nodeProps.action !== undefined && nodeProps.showButton === undefined && (
|
||||||
<div style={sectionGap}>
|
<div style={sectionGap}>
|
||||||
<label style={labelStyle}>Form Action URL</label>
|
<label style={labelStyle}>Form Action URL</label>
|
||||||
<input type="text" value={nodeProps.action || ''} onChange={(e) => setProp('action', e.target.value)} placeholder="https://..." style={inputStyle} />
|
<input type="text" value={nodeProps.action || ''} onChange={(e) => setProp('action', e.target.value)} placeholder="https://..." style={inputStyle} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* SearchBar: where the GET search request is submitted. */}
|
||||||
|
{nodeProps.showButton !== undefined && nodeProps.action !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Search Results Page</label>
|
||||||
|
<input type="text" value={nodeProps.action || ''} onChange={(e) => setProp('action', e.target.value)} placeholder="/ (site root) or /search" style={inputStyle} />
|
||||||
|
<p style={{ fontSize: 10, color: '#71717a', margin: '4px 0 0' }}>
|
||||||
|
Submits a GET request with the query as ?q=... to this URL.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{nodeProps.showButton !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={{ ...labelStyle, display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer' }}>
|
||||||
|
<input type="checkbox" checked={nodeProps.showButton !== false} onChange={(e) => setProp('showButton', e.target.checked)} />
|
||||||
|
Show Search Button
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{nodeProps.method !== undefined && (
|
{nodeProps.method !== undefined && (
|
||||||
<div style={sectionGap}>
|
<div style={sectionGap}>
|
||||||
<label style={labelStyle}>Method</label>
|
<label style={labelStyle}>Method</label>
|
||||||
@@ -142,6 +297,64 @@ export const FormStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProp
|
|||||||
<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 (per-side), border, shadow, opacity --
|
||||||
|
common enh-batch rollout, applies to the whole form family since
|
||||||
|
they all spread `style` onto their root element. */}
|
||||||
|
<CollapsibleSection title="Spacing, Border & Effects" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{ top: style.marginTop, right: style.marginRight, bottom: style.marginBottom, left: style.marginLeft }}
|
||||||
|
onChange={(side, v) => setPropStyle(`margin${SPACING_SIDE_KEYS.find((s) => s.side === side)!.suffix}`, v)}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding (per side)"
|
||||||
|
value={{ top: style.paddingTop, right: style.paddingRight, bottom: style.paddingBottom, left: style.paddingLeft }}
|
||||||
|
onChange={(side, v) => setPropStyle(`padding${SPACING_SIDE_KEYS.find((s) => s.side === side)!.suffix}`, v)}
|
||||||
|
/>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderValue(style.border)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Box 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 && style.opacity !== '' ? Math.round(Number(style.opacity) * 100) : 100}
|
||||||
|
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Animation & Visibility -- gated on the blank/false defaults added to
|
||||||
|
each owned component's craft.props (ContactForm, FormContainer,
|
||||||
|
InputField, TextareaField, FormButton, SubscribeForm, SearchBar).
|
||||||
|
No toHtml change needed: the export's buildDataAttrs() already
|
||||||
|
emits data-animation/data-hide-* from these exact prop names for
|
||||||
|
every node. */}
|
||||||
|
{nodeProps.animation !== undefined && (
|
||||||
|
<CollapsibleSection title="Animation & Visibility" defaultOpen={false}>
|
||||||
|
<AnimationControl
|
||||||
|
value={{ animation: nodeProps.animation, 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>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
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
|
|
||||||
CONTAINERS package's single shared panel (ContainerStylePanel, used for
|
|
||||||
Container / Section / Columns). 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 those 3 components rather than a genuinely
|
|
||||||
cross-package reusable control. Mirrors the equivalent helper in the
|
|
||||||
media package (mediaBoxModel.tsx) -- same shape, independently duplicated
|
|
||||||
per-package by design (packages are developed and merged in parallel).
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
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