Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54572f648a | ||
|
|
1d9460c173 | ||
|
|
8d69982a0b | ||
|
|
fb40e3ece4 | ||
|
|
9591fcb8a7 | ||
|
|
f80811318b |
Generated
+217
@@ -8,6 +8,15 @@
|
|||||||
"name": "whp-site-builder",
|
"name": "whp-site-builder",
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "^6.20.3",
|
||||||
|
"@codemirror/commands": "^6.10.4",
|
||||||
|
"@codemirror/lang-css": "^6.3.1",
|
||||||
|
"@codemirror/lang-html": "^6.4.11",
|
||||||
|
"@codemirror/lang-javascript": "^6.2.5",
|
||||||
|
"@codemirror/language": "^6.12.4",
|
||||||
|
"@codemirror/state": "^6.7.1",
|
||||||
|
"@codemirror/theme-one-dark": "^6.1.3",
|
||||||
|
"@codemirror/view": "^6.43.6",
|
||||||
"@craftjs/core": "^0.2.10",
|
"@craftjs/core": "^0.2.10",
|
||||||
"@craftjs/layers": "^0.2.7",
|
"@craftjs/layers": "^0.2.7",
|
||||||
"dompurify": "^3.4.5",
|
"dompurify": "^3.4.5",
|
||||||
@@ -373,6 +382,133 @@
|
|||||||
"specificity": "bin/cli.js"
|
"specificity": "bin/cli.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@codemirror/autocomplete": {
|
||||||
|
"version": "6.20.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.3.tgz",
|
||||||
|
"integrity": "sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/language": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.17.0",
|
||||||
|
"@lezer/common": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/commands": {
|
||||||
|
"version": "6.10.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.4.tgz",
|
||||||
|
"integrity": "sha512-Ryk9y9T0FFVF0cUGhAknveAyUOl/A1qReTFi+qPKtOh2Z9F4AUBz3XOrYD4ZEgZirdugVzHvd/2/Wcwy5OliTg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/language": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.7.0",
|
||||||
|
"@codemirror/view": "^6.27.0",
|
||||||
|
"@lezer/common": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/lang-css": {
|
||||||
|
"version": "6.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/lang-css/-/lang-css-6.3.1.tgz",
|
||||||
|
"integrity": "sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "^6.0.0",
|
||||||
|
"@codemirror/language": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@lezer/common": "^1.0.2",
|
||||||
|
"@lezer/css": "^1.1.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/lang-html": {
|
||||||
|
"version": "6.4.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/lang-html/-/lang-html-6.4.11.tgz",
|
||||||
|
"integrity": "sha512-9NsXp7Nwp891pQchI7gPdTwBuSuT3K65NGTHWHNJ55HjYcHLllr0rbIZNdOzas9ztc1EUVBlHou85FFZS4BNnw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "^6.0.0",
|
||||||
|
"@codemirror/lang-css": "^6.0.0",
|
||||||
|
"@codemirror/lang-javascript": "^6.0.0",
|
||||||
|
"@codemirror/language": "^6.4.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.17.0",
|
||||||
|
"@lezer/common": "^1.0.0",
|
||||||
|
"@lezer/css": "^1.1.0",
|
||||||
|
"@lezer/html": "^1.3.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/lang-javascript": {
|
||||||
|
"version": "6.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.5.tgz",
|
||||||
|
"integrity": "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "^6.0.0",
|
||||||
|
"@codemirror/language": "^6.6.0",
|
||||||
|
"@codemirror/lint": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.17.0",
|
||||||
|
"@lezer/common": "^1.0.0",
|
||||||
|
"@lezer/javascript": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/language": {
|
||||||
|
"version": "6.12.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.4.tgz",
|
||||||
|
"integrity": "sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.23.0",
|
||||||
|
"@lezer/common": "^1.5.0",
|
||||||
|
"@lezer/highlight": "^1.0.0",
|
||||||
|
"@lezer/lr": "^1.0.0",
|
||||||
|
"style-mod": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/lint": {
|
||||||
|
"version": "6.9.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.7.tgz",
|
||||||
|
"integrity": "sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.42.0",
|
||||||
|
"crelt": "^1.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/state": {
|
||||||
|
"version": "6.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.1.tgz",
|
||||||
|
"integrity": "sha512-9QzNDgE4EYDnAHfrTlR2lwiPciiOymLtwKK+8yHQzCc7GXhAP9xdEbEJFy2IWB1j9UGUl9BsgMmTo/ImA02T7A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@marijn/find-cluster-break": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/theme-one-dark": {
|
||||||
|
"version": "6.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/theme-one-dark/-/theme-one-dark-6.1.3.tgz",
|
||||||
|
"integrity": "sha512-NzBdIvEJmx6fjeremiGp3t/okrLPYT0d9orIc7AFun8oZcRk58aejkqhv6spnz4MLAevrKNPMQYXEWMg4s+sKA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/language": "^6.0.0",
|
||||||
|
"@codemirror/state": "^6.0.0",
|
||||||
|
"@codemirror/view": "^6.0.0",
|
||||||
|
"@lezer/highlight": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@codemirror/view": {
|
||||||
|
"version": "6.43.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.6.tgz",
|
||||||
|
"integrity": "sha512-EVunGSYN1wz1p75WY1s3Xg7t3i8Yol0kGZGizNdX9BUFgMFILYVe8/u6EVpo7Ff5PwbZuILb4QAq7IZoKzIEQA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@codemirror/state": "^6.7.0",
|
||||||
|
"crelt": "^1.0.6",
|
||||||
|
"style-mod": "^4.1.0",
|
||||||
|
"w3c-keyname": "^2.2.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@craftjs/core": {
|
"node_modules/@craftjs/core": {
|
||||||
"version": "0.2.12",
|
"version": "0.2.12",
|
||||||
"resolved": "https://registry.npmjs.org/@craftjs/core/-/core-0.2.12.tgz",
|
"resolved": "https://registry.npmjs.org/@craftjs/core/-/core-0.2.12.tgz",
|
||||||
@@ -1093,6 +1229,69 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@lezer/common": {
|
||||||
|
"version": "1.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz",
|
||||||
|
"integrity": "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@lezer/css": {
|
||||||
|
"version": "1.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/css/-/css-1.3.4.tgz",
|
||||||
|
"integrity": "sha512-N+tn9tej2hPvyKgHEApMOQfHczDJCwxrRFS3SPn9QjYN+uwHvEDnCgKRrb3mxDYxRS8sKMM8fhC3+lc04Abz5Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@lezer/common": "^1.2.0",
|
||||||
|
"@lezer/highlight": "^1.0.0",
|
||||||
|
"@lezer/lr": "^1.3.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@lezer/highlight": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@lezer/common": "^1.3.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@lezer/html": {
|
||||||
|
"version": "1.3.13",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/html/-/html-1.3.13.tgz",
|
||||||
|
"integrity": "sha512-oI7n6NJml729m7pjm9lvLvmXbdoMoi2f+1pwSDJkl9d68zGr7a9Btz8NdHTGQZtW2DA25ybeuv/SyDb9D5tseg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@lezer/common": "^1.2.0",
|
||||||
|
"@lezer/highlight": "^1.0.0",
|
||||||
|
"@lezer/lr": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@lezer/javascript": {
|
||||||
|
"version": "1.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.4.tgz",
|
||||||
|
"integrity": "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@lezer/common": "^1.2.0",
|
||||||
|
"@lezer/highlight": "^1.1.3",
|
||||||
|
"@lezer/lr": "^1.3.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@lezer/lr": {
|
||||||
|
"version": "1.4.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.10.tgz",
|
||||||
|
"integrity": "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@lezer/common": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@marijn/find-cluster-break": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@playwright/test": {
|
"node_modules/@playwright/test": {
|
||||||
"version": "1.59.1",
|
"version": "1.59.1",
|
||||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
|
||||||
@@ -1873,6 +2072,12 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/crelt": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/css-color-keywords": {
|
"node_modules/css-color-keywords": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz",
|
||||||
@@ -2686,6 +2891,12 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/style-mod": {
|
||||||
|
"version": "4.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",
|
||||||
|
"integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/styled-components": {
|
"node_modules/styled-components": {
|
||||||
"version": "6.3.12",
|
"version": "6.3.12",
|
||||||
"resolved": "https://registry.npmjs.org/styled-components/-/styled-components-6.3.12.tgz",
|
"resolved": "https://registry.npmjs.org/styled-components/-/styled-components-6.3.12.tgz",
|
||||||
@@ -3096,6 +3307,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/w3c-keyname": {
|
||||||
|
"version": "2.2.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
||||||
|
"integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/w3c-xmlserializer": {
|
"node_modules/w3c-xmlserializer": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,15 @@
|
|||||||
"test:unit:watch": "vitest"
|
"test:unit:watch": "vitest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@codemirror/autocomplete": "^6.20.3",
|
||||||
|
"@codemirror/commands": "^6.10.4",
|
||||||
|
"@codemirror/lang-css": "^6.3.1",
|
||||||
|
"@codemirror/lang-html": "^6.4.11",
|
||||||
|
"@codemirror/lang-javascript": "^6.2.5",
|
||||||
|
"@codemirror/language": "^6.12.4",
|
||||||
|
"@codemirror/state": "^6.7.1",
|
||||||
|
"@codemirror/theme-one-dark": "^6.1.3",
|
||||||
|
"@codemirror/view": "^6.43.6",
|
||||||
"@craftjs/core": "^0.2.10",
|
"@craftjs/core": "^0.2.10",
|
||||||
"@craftjs/layers": "^0.2.7",
|
"@craftjs/layers": "^0.2.7",
|
||||||
"dompurify": "^3.4.5",
|
"dompurify": "^3.4.5",
|
||||||
|
|||||||
@@ -20,3 +20,14 @@ describe('Footer.toHtml text escaping (attacker-controlled `text` prop)', () =>
|
|||||||
expect(html).toContain('© 2026 MySite. All rights reserved.');
|
expect(html).toContain('© 2026 MySite. All rights reserved.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Footer (F4: box-model + animation + visibility props on craft.props)', () => {
|
||||||
|
test('craft.props includes animation/visibility defaults so the panel controls always render', () => {
|
||||||
|
const craftProps = (Footer as any).craft.props;
|
||||||
|
expect(craftProps).toHaveProperty('animation', 'none');
|
||||||
|
expect(craftProps).toHaveProperty('animationDelay', '0');
|
||||||
|
expect(craftProps).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import { escapeHtml } from '../../utils/escape';
|
|||||||
interface FooterProps {
|
interface FooterProps {
|
||||||
text?: string;
|
text?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Footer: UserComponent<FooterProps> = ({
|
export const Footer: UserComponent<FooterProps> = ({
|
||||||
@@ -92,6 +97,11 @@ Footer.craft = {
|
|||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
padding: '24px 20px',
|
padding: '24px 20px',
|
||||||
},
|
},
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
animation: 'none',
|
||||||
|
animationDelay: '0',
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -43,6 +43,29 @@ describe('Logo.toHtml image src/alt sanitization (type="image")', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Logo.toHtml download attribute (F3: link-to-file toggle)', () => {
|
||||||
|
test('download:true emits the download attribute', () => {
|
||||||
|
const { html } = toHtml({ href: '/resume.pdf', download: true, text: 'Resume' }, '');
|
||||||
|
expect(html).toMatch(/<a href="\/resume\.pdf" download/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('no download prop -> no download attribute emitted', () => {
|
||||||
|
const { html } = toHtml({ href: '/', text: 'MySite' }, '');
|
||||||
|
expect(html).not.toContain('download');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Logo (F4: box-model + animation + visibility props on craft.props)', () => {
|
||||||
|
test('craft.props includes animation/visibility defaults so the panel controls always render', () => {
|
||||||
|
const craftProps = (Logo as any).craft.props;
|
||||||
|
expect(craftProps).toHaveProperty('animation', 'none');
|
||||||
|
expect(craftProps).toHaveProperty('animationDelay', '0');
|
||||||
|
expect(craftProps).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Logo.toHtml text-logo styling sanitization', () => {
|
describe('Logo.toHtml text-logo styling sanitization', () => {
|
||||||
test('a quote-breakout color does not escape the span style attribute', () => {
|
test('a quote-breakout color does not escape the span style attribute', () => {
|
||||||
const malicious = 'red" onmouseover="alert(1)';
|
const malicious = 'red" onmouseover="alert(1)';
|
||||||
|
|||||||
@@ -12,11 +12,18 @@ interface LogoProps {
|
|||||||
imageSrc?: string;
|
imageSrc?: string;
|
||||||
imageWidth?: string;
|
imageWidth?: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
|
/** Adds the `download` attribute to the exported anchor (F3: link to a file). */
|
||||||
|
download?: boolean;
|
||||||
fontFamily?: string;
|
fontFamily?: string;
|
||||||
fontSize?: string;
|
fontSize?: string;
|
||||||
fontWeight?: string;
|
fontWeight?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- Component ---------- */
|
/* ---------- Component ---------- */
|
||||||
@@ -27,6 +34,7 @@ export const Logo: UserComponent<LogoProps> = ({
|
|||||||
imageSrc = '',
|
imageSrc = '',
|
||||||
imageWidth = '120px',
|
imageWidth = '120px',
|
||||||
href = '/',
|
href = '/',
|
||||||
|
download = false,
|
||||||
fontFamily = 'Inter, sans-serif',
|
fontFamily = 'Inter, sans-serif',
|
||||||
fontSize = '20px',
|
fontSize = '20px',
|
||||||
fontWeight = '700',
|
fontWeight = '700',
|
||||||
@@ -44,6 +52,7 @@ export const Logo: UserComponent<LogoProps> = ({
|
|||||||
<a
|
<a
|
||||||
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||||
href={href}
|
href={href}
|
||||||
|
download={download || undefined}
|
||||||
onClick={(e) => e.preventDefault()}
|
onClick={(e) => e.preventDefault()}
|
||||||
style={{
|
style={{
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
@@ -87,7 +96,13 @@ Logo.craft = {
|
|||||||
fontSize: '20px',
|
fontSize: '20px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
color: undefined,
|
color: undefined,
|
||||||
|
download: false,
|
||||||
style: {},
|
style: {},
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
animation: 'none',
|
||||||
|
animationDelay: '0',
|
||||||
} as LogoProps,
|
} as LogoProps,
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -122,8 +137,9 @@ Logo.craft = {
|
|||||||
flexShrink: '0',
|
flexShrink: '0',
|
||||||
...props.style,
|
...props.style,
|
||||||
});
|
});
|
||||||
|
const downloadAttr = props.download ? ' download' : '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: `<a href="${escapeAttr(safeUrl(href))}"${aStyle ? ` style="${aStyle}"` : ''}>${innerHtml}</a>`,
|
html: `<a href="${escapeAttr(safeUrl(href))}"${downloadAttr}${aStyle ? ` style="${aStyle}"` : ''}>${innerHtml}</a>`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,29 @@ describe('Menu.toHtml deterministic + unique scope ids (thread node id, no Math.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Menu.toHtml download attribute (F3: link-to-file toggle)', () => {
|
||||||
|
test('a link with download:true emits the download attribute', () => {
|
||||||
|
const { html } = toHtml({ links: [{ text: 'Brochure', href: '/brochure.pdf', download: true }] }, '', 'node-dl1');
|
||||||
|
expect(html).toMatch(/<a href="\/brochure\.pdf"[^>]* download[^>]*>Brochure<\/a>/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a link without download does not emit the attribute', () => {
|
||||||
|
const { html } = toHtml({ links: [{ text: 'Home', href: '/' }] }, '', 'node-dl2');
|
||||||
|
expect(html).not.toContain(' download');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Menu (F4: box-model + animation + visibility props on craft.props)', () => {
|
||||||
|
test('craft.props includes animation/visibility defaults so the panel controls always render', () => {
|
||||||
|
const craftProps = (Menu as any).craft.props;
|
||||||
|
expect(craftProps).toHaveProperty('animation', 'none');
|
||||||
|
expect(craftProps).toHaveProperty('animationDelay', '0');
|
||||||
|
expect(craftProps).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Menu.toHtml XSS hardening (linkHoverColor into <style>)', () => {
|
describe('Menu.toHtml XSS hardening (linkHoverColor into <style>)', () => {
|
||||||
test('a linkHoverColor value containing </style><script> is neutralized', () => {
|
test('a linkHoverColor value containing </style><script> is neutralized', () => {
|
||||||
const malicious = '#fff}</style><script>alert(1)</script><style>{';
|
const malicious = '#fff}</style><script>alert(1)</script><style>{';
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ interface MenuLink {
|
|||||||
href: string;
|
href: string;
|
||||||
isExternal?: boolean;
|
isExternal?: boolean;
|
||||||
isCta?: boolean;
|
isCta?: boolean;
|
||||||
|
/** Adds the `download` attribute to the exported anchor (F3: links to files). */
|
||||||
|
download?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuProps {
|
interface MenuProps {
|
||||||
@@ -23,6 +25,11 @@ interface MenuProps {
|
|||||||
orientation?: 'horizontal' | 'vertical';
|
orientation?: 'horizontal' | 'vertical';
|
||||||
fontSize?: string;
|
fontSize?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- Defaults ---------- */
|
/* ---------- Defaults ---------- */
|
||||||
@@ -75,6 +82,7 @@ export const Menu: UserComponent<MenuProps> = ({
|
|||||||
href={link.href}
|
href={link.href}
|
||||||
target={link.isExternal ? '_blank' : undefined}
|
target={link.isExternal ? '_blank' : undefined}
|
||||||
rel={link.isExternal ? 'noopener noreferrer' : undefined}
|
rel={link.isExternal ? 'noopener noreferrer' : undefined}
|
||||||
|
download={link.download || undefined}
|
||||||
onClick={(e) => e.preventDefault()}
|
onClick={(e) => e.preventDefault()}
|
||||||
onMouseEnter={() => setHoveredLink(i)}
|
onMouseEnter={() => setHoveredLink(i)}
|
||||||
onMouseLeave={() => setHoveredLink(null)}
|
onMouseLeave={() => setHoveredLink(null)}
|
||||||
@@ -114,6 +122,11 @@ Menu.craft = {
|
|||||||
orientation: 'horizontal',
|
orientation: 'horizontal',
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
style: {},
|
style: {},
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
animation: 'none',
|
||||||
|
animationDelay: '0',
|
||||||
} as MenuProps,
|
} as MenuProps,
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -162,6 +175,7 @@ Menu.craft = {
|
|||||||
|
|
||||||
const linksHtml = links.map((link) => {
|
const linksHtml = links.map((link) => {
|
||||||
const target = link.isExternal ? ' target="_blank" rel="noopener noreferrer"' : '';
|
const target = link.isExternal ? ' target="_blank" rel="noopener noreferrer"' : '';
|
||||||
|
const downloadAttr = link.download ? ' download' : '';
|
||||||
const cls = link.isCta ? `${scope}-cta` : `${scope}-link`;
|
const cls = link.isCta ? `${scope}-cta` : `${scope}-link`;
|
||||||
const linkStyle = cssPropsToString({
|
const linkStyle = cssPropsToString({
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
@@ -173,7 +187,7 @@ Menu.craft = {
|
|||||||
borderRadius: link.isCta ? '6px' : '0',
|
borderRadius: link.isCta ? '6px' : '0',
|
||||||
transition: 'color 0.15s, background-color 0.15s',
|
transition: 'color 0.15s, background-color 0.15s',
|
||||||
});
|
});
|
||||||
return `<a href="${escapeAttr(safeUrl(link.href || '#'))}" class="${cls}"${target}${linkStyle ? ` style="${linkStyle}"` : ''}>${escapeHtml(link.text)}</a>`;
|
return `<a href="${escapeAttr(safeUrl(link.href || '#'))}" class="${cls}"${target}${downloadAttr}${linkStyle ? ` style="${linkStyle}"` : ''}>${escapeHtml(link.text)}</a>`;
|
||||||
}).join('\n ');
|
}).join('\n ');
|
||||||
|
|
||||||
const hoverCss = `<style>
|
const hoverCss = `<style>
|
||||||
|
|||||||
@@ -83,6 +83,29 @@ describe('Navbar.toHtml node-scoped ids/hover styles (M-1: two navbars must not
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Navbar.toHtml download attribute (F3: link-to-file toggle)', () => {
|
||||||
|
test('a link with download:true emits the download attribute', () => {
|
||||||
|
const { html } = toHtml({ links: [{ text: 'Brochure', href: '/brochure.pdf', download: true }] }, '', 'node-dl1');
|
||||||
|
expect(html).toMatch(/<a href="\/brochure\.pdf"[^>]* download[^>]*>Brochure<\/a>/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a link without download does not emit the attribute', () => {
|
||||||
|
const { html } = toHtml({ links: [{ text: 'Home', href: '/' }] }, '', 'node-dl2');
|
||||||
|
expect(html).not.toContain(' download');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Navbar (F4: box-model + animation + visibility props on craft.props)', () => {
|
||||||
|
test('craft.props includes animation/visibility defaults so the panel controls always render', () => {
|
||||||
|
const craftProps = (Navbar as any).craft.props;
|
||||||
|
expect(craftProps).toHaveProperty('animation', 'none');
|
||||||
|
expect(craftProps).toHaveProperty('animationDelay', '0');
|
||||||
|
expect(craftProps).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(craftProps).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Navbar.toHtml XSS hardening (hoverColor/backgroundColor/ctaColor into <style>)', () => {
|
describe('Navbar.toHtml XSS hardening (hoverColor/backgroundColor/ctaColor into <style>)', () => {
|
||||||
test('a hoverColor value containing </style><script> is neutralized in the hover <style> block', () => {
|
test('a hoverColor value containing </style><script> is neutralized in the hover <style> block', () => {
|
||||||
const malicious = '#fff}</style><script>alert(1)</script><style>{';
|
const malicious = '#fff}</style><script>alert(1)</script><style>{';
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ interface NavLink {
|
|||||||
href: string;
|
href: string;
|
||||||
isExternal?: boolean;
|
isExternal?: boolean;
|
||||||
isCta?: boolean;
|
isCta?: boolean;
|
||||||
|
/** Adds the `download` attribute to the exported anchor (F3: links to files). */
|
||||||
|
download?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavbarProps {
|
interface NavbarProps {
|
||||||
@@ -33,6 +35,11 @@ interface NavbarProps {
|
|||||||
isSticky?: boolean;
|
isSticky?: boolean;
|
||||||
showMobileMenu?: boolean;
|
showMobileMenu?: boolean;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- Defaults ---------- */
|
/* ---------- Defaults ---------- */
|
||||||
@@ -149,6 +156,7 @@ export const Navbar: UserComponent<NavbarProps> = ({
|
|||||||
href={link.href}
|
href={link.href}
|
||||||
target={link.isExternal ? '_blank' : undefined}
|
target={link.isExternal ? '_blank' : undefined}
|
||||||
rel={link.isExternal ? 'noopener noreferrer' : undefined}
|
rel={link.isExternal ? 'noopener noreferrer' : undefined}
|
||||||
|
download={link.download || undefined}
|
||||||
onClick={(e) => e.preventDefault()}
|
onClick={(e) => e.preventDefault()}
|
||||||
onMouseEnter={() => setHoveredLink(i)}
|
onMouseEnter={() => setHoveredLink(i)}
|
||||||
onMouseLeave={() => setHoveredLink(null)}
|
onMouseLeave={() => setHoveredLink(null)}
|
||||||
@@ -200,6 +208,11 @@ Navbar.craft = {
|
|||||||
style: {
|
style: {
|
||||||
borderBottom: '1px solid #e4e4e7',
|
borderBottom: '1px solid #e4e4e7',
|
||||||
},
|
},
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
animation: 'none',
|
||||||
|
animationDelay: '0',
|
||||||
} as NavbarProps,
|
} as NavbarProps,
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -308,6 +321,7 @@ Navbar.craft = {
|
|||||||
// Add CSS class to each link for hover
|
// Add CSS class to each link for hover
|
||||||
const linksHtmlWithClass = links.map((link) => {
|
const linksHtmlWithClass = links.map((link) => {
|
||||||
const target = link.isExternal ? ' target="_blank" rel="noopener noreferrer"' : '';
|
const target = link.isExternal ? ' target="_blank" rel="noopener noreferrer"' : '';
|
||||||
|
const downloadAttr = link.download ? ' download' : '';
|
||||||
const cls = link.isCta ? 'navbar-cta' : 'navbar-link';
|
const cls = link.isCta ? 'navbar-cta' : 'navbar-link';
|
||||||
const linkStyle = cssPropsToString({
|
const linkStyle = cssPropsToString({
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
@@ -319,7 +333,7 @@ Navbar.craft = {
|
|||||||
borderRadius: link.isCta ? '6px' : '0',
|
borderRadius: link.isCta ? '6px' : '0',
|
||||||
transition: 'color 0.15s, background-color 0.15s',
|
transition: 'color 0.15s, background-color 0.15s',
|
||||||
});
|
});
|
||||||
return `<a href="${escapeAttr(safeUrl(link.href || "#"))}" class="${cls}"${target}${linkStyle ? ` style="${linkStyle}"` : ''}>${escapeHtml(link.text)}</a>`;
|
return `<a href="${escapeAttr(safeUrl(link.href || "#"))}" class="${cls}"${target}${downloadAttr}${linkStyle ? ` style="${linkStyle}"` : ''}>${escapeHtml(link.text)}</a>`;
|
||||||
}).join('\n ');
|
}).join('\n ');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -94,3 +94,68 @@ export const DEVICE_WIDTHS: Record<string, string> = {
|
|||||||
tablet: '768px',
|
tablet: '768px',
|
||||||
mobile: '375px',
|
mobile: '375px',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ---------- ENH-Foundation shared presets ----------
|
||||||
|
Consumed by the reusable StylePanel controls in
|
||||||
|
src/panels/right/styles/shared.tsx (SizeControl, AspectRatioControl,
|
||||||
|
BorderControl, etc). Kept in the `{ label, value }` shape used throughout
|
||||||
|
this file so they drop straight into PresetButtonGrid / ColorSwatchGrid. */
|
||||||
|
|
||||||
|
// Width/height preset row used by SizeControl (image + video sizing).
|
||||||
|
export const SIZE_PRESETS = [
|
||||||
|
{ label: '25%', value: '25%' },
|
||||||
|
{ label: '50%', value: '50%' },
|
||||||
|
{ label: '75%', value: '75%' },
|
||||||
|
{ label: '100%', value: '100%' },
|
||||||
|
{ label: 'Auto', value: 'auto' },
|
||||||
|
{ label: 'Full', value: '100vw' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// CSS `aspect-ratio` values. 'Original' (empty string) clears the property.
|
||||||
|
export const ASPECT_RATIOS = [
|
||||||
|
{ label: 'Original', value: '' },
|
||||||
|
{ label: '1:1', value: '1 / 1' },
|
||||||
|
{ label: '4:3', value: '4 / 3' },
|
||||||
|
{ label: '3:2', value: '3 / 2' },
|
||||||
|
{ label: '16:9', value: '16 / 9' },
|
||||||
|
{ label: '4:5', value: '4 / 5' },
|
||||||
|
{ label: '9:16', value: '9 / 16' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// box-shadow presets; 'Colored' is the color-aware option (accent-tinted).
|
||||||
|
export const SHADOW_PRESETS = [
|
||||||
|
{ label: 'None', value: 'none' },
|
||||||
|
{ label: 'S', value: '0 1px 2px rgba(0,0,0,0.08)' },
|
||||||
|
{ label: 'M', value: '0 4px 8px rgba(0,0,0,0.12)' },
|
||||||
|
{ label: 'L', value: '0 10px 24px rgba(0,0,0,0.18)' },
|
||||||
|
{ label: 'Colored', value: '0 8px 20px rgba(59,130,246,0.35)' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const LINE_HEIGHTS = [
|
||||||
|
{ label: 'Tight', value: '1.1' },
|
||||||
|
{ label: 'Snug', value: '1.25' },
|
||||||
|
{ label: 'Normal', value: '1.5' },
|
||||||
|
{ label: 'Relaxed', value: '1.75' },
|
||||||
|
{ label: 'Loose', value: '2' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const LETTER_SPACINGS = [
|
||||||
|
{ label: 'Tight', value: '-0.02em' },
|
||||||
|
{ label: 'Normal', value: 'normal' },
|
||||||
|
{ label: 'Wide', value: '0.05em' },
|
||||||
|
{ label: 'Wider', value: '0.1em' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const OBJECT_FIT = [
|
||||||
|
{ label: 'Cover', value: 'cover' },
|
||||||
|
{ label: 'Contain', value: 'contain' },
|
||||||
|
{ label: 'Fill', value: 'fill' },
|
||||||
|
{ label: 'None', value: 'none' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export const BORDER_STYLES = [
|
||||||
|
{ label: 'None', value: 'none' },
|
||||||
|
{ label: 'Solid', value: 'solid' },
|
||||||
|
{ label: 'Dashed', value: 'dashed' },
|
||||||
|
{ label: 'Dotted', value: 'dotted' },
|
||||||
|
];
|
||||||
|
|||||||
@@ -0,0 +1,282 @@
|
|||||||
|
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
|
import React from 'react';
|
||||||
|
import { createRoot, Root } from 'react-dom/client';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
|
/* NavStylePanel (via useNodeProp/LinkPicker in this file) needs useEditor
|
||||||
|
from @craftjs/core and usePages from PageContext. Mock both following the
|
||||||
|
DOM-harness pattern used across this repo's other *StylePanel tests (no
|
||||||
|
@testing-library/react here) -- PageContext itself is Wave-2's territory,
|
||||||
|
this package only READS pages via usePages(), so mocking it is the
|
||||||
|
correct boundary for these tests. */
|
||||||
|
const setPropSpy = vi.fn((_id: string, updater: (p: any) => void) => {
|
||||||
|
updater(lastProps);
|
||||||
|
});
|
||||||
|
let lastProps: any;
|
||||||
|
|
||||||
|
vi.mock('@craftjs/core', () => ({
|
||||||
|
useEditor: () => ({ actions: { setProp: setPropSpy } }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
let mockPages: { id: string; name: string; slug: string; craftState: string | null }[] = [];
|
||||||
|
vi.mock('../../../state/PageContext', () => ({
|
||||||
|
usePages: () => ({ pages: mockPages }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../../ui/AssetPicker', () => ({
|
||||||
|
AssetPicker: () => null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { NavStylePanel, LinkPicker, pageHref } from './NavStylePanel';
|
||||||
|
|
||||||
|
let container: HTMLDivElement;
|
||||||
|
let root: Root;
|
||||||
|
|
||||||
|
function render(ui: React.ReactElement) {
|
||||||
|
container = document.createElement('div');
|
||||||
|
document.body.appendChild(container);
|
||||||
|
act(() => {
|
||||||
|
root = createRoot(container);
|
||||||
|
root.render(ui);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rerender(ui: React.ReactElement) {
|
||||||
|
act(() => { root.render(ui); });
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount() {
|
||||||
|
act(() => { root.unmount(); });
|
||||||
|
container.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setValue(el: HTMLInputElement | HTMLSelectElement, value: string) {
|
||||||
|
const proto = el instanceof HTMLSelectElement ? window.HTMLSelectElement.prototype : window.HTMLInputElement.prototype;
|
||||||
|
const setter = Object.getOwnPropertyDescriptor(proto, 'value')!.set!;
|
||||||
|
act(() => {
|
||||||
|
setter.call(el, value);
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function click(el: Element | null) {
|
||||||
|
act(() => { (el as HTMLElement).dispatchEvent(new MouseEvent('click', { bubbles: true })); });
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setPropSpy.mockClear();
|
||||||
|
mockPages = [
|
||||||
|
{ id: 'home', name: 'Home', slug: 'index', craftState: null },
|
||||||
|
{ id: 'about', name: 'About', slug: 'about', craftState: null },
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (container) unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('pageHref (landing page is always "/")', () => {
|
||||||
|
test('index 0 (landing page) -> "/"', () => {
|
||||||
|
expect(pageHref(mockPages[0], 0)).toBe('/');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('any other page -> "/{slug}"', () => {
|
||||||
|
expect(pageHref(mockPages[1], 1)).toBe('/about');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('LinkPicker (F1: link-to-page picker + manual URL/anchor/tel/mailto)', () => {
|
||||||
|
test('a value matching a page href starts in "Page" mode and lists every page', () => {
|
||||||
|
render(<LinkPicker value="/about" onChange={vi.fn()} />);
|
||||||
|
const [modeSelect] = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
expect(modeSelect.value).toBe('page');
|
||||||
|
const optionText = Array.from(container.querySelectorAll('option')).map((o) => o.textContent);
|
||||||
|
expect(optionText).toContain('Home');
|
||||||
|
expect(optionText).toContain('About');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('picking a different page from the page dropdown emits that page\'s href', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<LinkPicker value="/about" onChange={onChange} />);
|
||||||
|
const [, pageSelect] = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
setValue(pageSelect, '/');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('/');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a "#section" value starts in Anchor mode', () => {
|
||||||
|
render(<LinkPicker value="#pricing" onChange={vi.fn()} />);
|
||||||
|
const [modeSelect] = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
expect(modeSelect.value).toBe('anchor');
|
||||||
|
const input = container.querySelector('input[type="text"]') as HTMLInputElement;
|
||||||
|
expect(input.value).toBe('#pricing');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('switching mode to Anchor seeds a bare "#"', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<LinkPicker value="/about" onChange={onChange} />);
|
||||||
|
const [modeSelect] = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
setValue(modeSelect, 'anchor');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('#');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('mailto: helper strips the scheme for editing and re-adds it on change', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<LinkPicker value="mailto:foo@example.com" onChange={onChange} />);
|
||||||
|
const input = container.querySelector('input[type="text"]') as HTMLInputElement;
|
||||||
|
expect(input.value).toBe('foo@example.com');
|
||||||
|
setValue(input, 'bar@example.com');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('mailto:bar@example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tel: helper strips the scheme for editing and re-adds it on change', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<LinkPicker value="tel:5551234567" onChange={onChange} />);
|
||||||
|
const input = container.querySelector('input[type="text"]') as HTMLInputElement;
|
||||||
|
expect(input.value).toBe('5551234567');
|
||||||
|
setValue(input, '5559876543');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('tel:5559876543');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a plain https:// URL falls back to Custom URL mode', () => {
|
||||||
|
render(<LinkPicker value="https://example.com" onChange={vi.fn()} />);
|
||||||
|
const [modeSelect] = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
expect(modeSelect.value).toBe('url');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('NavStylePanel Links section: href set via LinkPicker (F1 wired into the panel)', () => {
|
||||||
|
test('choosing a page for a Navbar link writes that page\'s href onto the link', () => {
|
||||||
|
lastProps = {
|
||||||
|
links: [{ text: 'Home', href: '/old-home' }],
|
||||||
|
};
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
const selects = Array.from(container.querySelectorAll('select')) as HTMLSelectElement[];
|
||||||
|
// First select for the one link item is its LinkPicker mode select (the
|
||||||
|
// href starts as a Custom URL, so it opens on "url" mode); switch it to
|
||||||
|
// "page" then pick the About page from the resulting page dropdown.
|
||||||
|
const modeSelect = selects[0];
|
||||||
|
setValue(modeSelect, 'page');
|
||||||
|
expect(setPropSpy).toHaveBeenCalled();
|
||||||
|
expect(lastProps.links[0].href).toBe('/'); // defaults to the first page
|
||||||
|
|
||||||
|
// The mock setProp mutates `lastProps` in place rather than triggering a
|
||||||
|
// real Craft.js state update, so force a re-render (passing the same,
|
||||||
|
// now-mutated, object) to get the LinkPicker to reflect its new "page"
|
||||||
|
// mode and render the page <select>.
|
||||||
|
rerender(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
const pageSelect = Array.from(container.querySelectorAll('select'))[1] as HTMLSelectElement;
|
||||||
|
setValue(pageSelect, '/about');
|
||||||
|
expect(lastProps.links[0].href).toBe('/about');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toggling the Download checkbox for a link sets download:true', () => {
|
||||||
|
lastProps = { links: [{ text: 'Brochure', href: '/brochure.pdf' }] };
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
const checkbox = container.querySelector('input[type="checkbox"]') as HTMLInputElement;
|
||||||
|
act(() => { checkbox.click(); });
|
||||||
|
expect(lastProps.links[0].download).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('NavStylePanel: "Sync links with Pages" (F2, regression vs legacy builder)', () => {
|
||||||
|
test('populates links from the mocked pages list and preserves the CTA link', () => {
|
||||||
|
lastProps = {
|
||||||
|
links: [
|
||||||
|
{ text: 'Old Home', href: '/old' },
|
||||||
|
{ text: 'Old About', href: '/old-about' },
|
||||||
|
{ text: 'Get Started', href: '#signup', isCta: true },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
const syncBtn = Array.from(container.querySelectorAll('button'))
|
||||||
|
.find((b) => b.textContent?.includes('Sync links with Pages'))!;
|
||||||
|
expect(syncBtn).toBeTruthy();
|
||||||
|
click(syncBtn);
|
||||||
|
|
||||||
|
expect(lastProps.links).toEqual([
|
||||||
|
{ text: 'Home', href: '/' },
|
||||||
|
{ text: 'About', href: '/about' },
|
||||||
|
{ text: 'Get Started', href: '#signup', isCta: true },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('with no CTA link, sync just replaces links 1:1 with the pages list', () => {
|
||||||
|
lastProps = { links: [{ text: 'Stale', href: '/stale' }] };
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
|
||||||
|
const syncBtn = Array.from(container.querySelectorAll('button'))
|
||||||
|
.find((b) => b.textContent?.includes('Sync links with Pages'))!;
|
||||||
|
click(syncBtn);
|
||||||
|
|
||||||
|
expect(lastProps.links).toEqual([
|
||||||
|
{ text: 'Home', href: '/' },
|
||||||
|
{ text: 'About', href: '/about' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the Links section (and its Sync button) is not shown for Footer (no `links` prop)', () => {
|
||||||
|
lastProps = { text: '© 2026' };
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
const syncBtn = Array.from(container.querySelectorAll('button'))
|
||||||
|
.find((b) => b.textContent?.includes('Sync links with Pages'));
|
||||||
|
expect(syncBtn).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/** The Spacing/Border & Effects/Animation/Visibility CollapsibleSections all
|
||||||
|
* default closed (defaultOpen={false}, matching the pre-existing "Spacing"
|
||||||
|
* section's convention) -- open one by clicking its header button before
|
||||||
|
* asserting on / interacting with its contents. */
|
||||||
|
function openSection(title: string) {
|
||||||
|
const header = Array.from(container.querySelectorAll('button'))
|
||||||
|
.find((b) => b.textContent?.includes(title))!;
|
||||||
|
click(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('NavStylePanel: box-model + animation + visibility controls always present', () => {
|
||||||
|
test('Spacing (Margin/Padding), Border & Effects, Animation, and Visibility sections render for a Navbar', () => {
|
||||||
|
lastProps = {
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
|
style: {},
|
||||||
|
animation: 'none',
|
||||||
|
animationDelay: '0',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
|
};
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
openSection('Spacing');
|
||||||
|
openSection('Border & Effects');
|
||||||
|
openSection('Animation');
|
||||||
|
openSection('Visibility');
|
||||||
|
expect(container.querySelector('[data-testid="spacing-control"]')).toBeTruthy();
|
||||||
|
expect(container.querySelector('[data-testid="border-control"]')).toBeTruthy();
|
||||||
|
expect(container.querySelector('[data-testid="animation-control"]')).toBeTruthy();
|
||||||
|
expect(container.querySelector('[data-testid="visibility-control"]')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checking "Hide on Mobile" writes hideOnMobile:true via setProp', () => {
|
||||||
|
lastProps = { hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false };
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
openSection('Visibility');
|
||||||
|
const checkbox = container.querySelector('[data-testid="visibility-hideOnMobile"]') as HTMLInputElement;
|
||||||
|
act(() => {
|
||||||
|
checkbox.click();
|
||||||
|
});
|
||||||
|
expect(lastProps.hideOnMobile).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('picking an entrance animation writes animation via setProp', () => {
|
||||||
|
lastProps = { animation: 'none', animationDelay: '0' };
|
||||||
|
render(<NavStylePanel selectedId="node1" nodeProps={lastProps} />);
|
||||||
|
openSection('Animation');
|
||||||
|
const fadeInBtn = Array.from(container.querySelectorAll('[data-testid="animation-control"] button'))
|
||||||
|
.find((b) => b.textContent === 'Fade In')!;
|
||||||
|
click(fadeInBtn);
|
||||||
|
expect(lastProps.animation).toBe('fade-in');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
|
|||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
import {
|
import {
|
||||||
SPACING_PRESETS,
|
SPACING_PRESETS,
|
||||||
|
SHADOW_PRESETS,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
@@ -16,13 +17,145 @@ import {
|
|||||||
smallInputStyle,
|
smallInputStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { AssetPicker } from '../../../ui/AssetPicker';
|
import { AssetPicker } from '../../../ui/AssetPicker';
|
||||||
|
import { usePages } from '../../../state/PageContext';
|
||||||
|
import { PageData } from '../../../types';
|
||||||
|
|
||||||
/* ---------- NAV / MENU / LOGO ---------- */
|
/* ---------- Link-to-page helpers (F1/F2: link picker + Sync with Pages) ----------
|
||||||
|
Mirrors the export convention used elsewhere: the first page is always the
|
||||||
|
landing page and publishes to '/', every other page publishes to '/{slug}'.
|
||||||
|
See PageContext.tsx's uniqueSlug/slugify and the landing-page-lock comment
|
||||||
|
in renamePage() for why index 0 is special-cased this way. */
|
||||||
|
export function pageHref(page: PageData, index: number): string {
|
||||||
|
return index === 0 ? '/' : `/${page.slug}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
type LinkMode = 'page' | 'url' | 'anchor' | 'tel' | 'mailto';
|
||||||
|
|
||||||
|
function detectLinkMode(value: string, pageHrefs: string[]): LinkMode {
|
||||||
|
const v = value || '';
|
||||||
|
if (pageHrefs.includes(v)) return 'page';
|
||||||
|
if (v.startsWith('#')) return 'anchor';
|
||||||
|
if (v.startsWith('tel:')) return 'tel';
|
||||||
|
if (v.startsWith('mailto:')) return 'mailto';
|
||||||
|
return 'url';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- LinkPicker ----------
|
||||||
|
Reused for every link-href field in this panel (standalone Logo's href,
|
||||||
|
Navbar's logoUrl, and each Navbar/Menu link item's href): a dropdown of
|
||||||
|
the site's PAGES (read-only via usePages() -- PageContext itself is
|
||||||
|
Wave-2's territory) plus manual URL / #anchor / tel: / mailto: entry.
|
||||||
|
safeUrl (in toHtml) already allows tel:/mailto: schemes, so no export-side
|
||||||
|
change is needed for those. */
|
||||||
|
interface LinkPickerProps {
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}
|
||||||
|
export const LinkPicker: React.FC<LinkPickerProps> = ({ value, onChange }) => {
|
||||||
|
const { pages } = usePages();
|
||||||
|
const pageOptions = pages.map((p, i) => ({ id: p.id, name: p.name, href: pageHref(p, i) }));
|
||||||
|
const mode = detectLinkMode(value || '', pageOptions.map((p) => p.href));
|
||||||
|
|
||||||
|
const switchMode = (next: LinkMode) => {
|
||||||
|
if (next === mode) return;
|
||||||
|
if (next === 'page') onChange(pageOptions[0]?.href || '/');
|
||||||
|
else if (next === 'anchor') onChange('#');
|
||||||
|
else if (next === 'tel') onChange('tel:');
|
||||||
|
else if (next === 'mailto') onChange('mailto:');
|
||||||
|
else onChange('');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={sectionGap} data-testid="link-picker">
|
||||||
|
<label style={labelStyle}>Link</label>
|
||||||
|
<select
|
||||||
|
value={mode}
|
||||||
|
onChange={(e) => switchMode(e.target.value as LinkMode)}
|
||||||
|
style={{ ...inputStyle, marginBottom: 4, cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
<option value="page">Page</option>
|
||||||
|
<option value="url">Custom URL</option>
|
||||||
|
<option value="anchor">Anchor (#section)</option>
|
||||||
|
<option value="tel">Phone (tel:)</option>
|
||||||
|
<option value="mailto">Email (mailto:)</option>
|
||||||
|
</select>
|
||||||
|
{mode === 'page' && (
|
||||||
|
pageOptions.length > 0 ? (
|
||||||
|
<select value={value} onChange={(e) => onChange(e.target.value)} style={inputStyle}>
|
||||||
|
{pageOptions.map((p) => (
|
||||||
|
<option key={p.id} value={p.href}>{p.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
) : (
|
||||||
|
<div style={{ fontSize: 11, color: '#71717a' }}>No pages yet</div>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
{mode === 'anchor' && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={value || ''}
|
||||||
|
onChange={(e) => onChange(e.target.value.startsWith('#') ? e.target.value : `#${e.target.value}`)}
|
||||||
|
placeholder="#section-id"
|
||||||
|
style={inputStyle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{mode === 'tel' && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={(value || '').replace(/^tel:/, '')}
|
||||||
|
onChange={(e) => onChange(`tel:${e.target.value}`)}
|
||||||
|
placeholder="+15551234567"
|
||||||
|
style={inputStyle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{mode === 'mailto' && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={(value || '').replace(/^mailto:/, '')}
|
||||||
|
onChange={(e) => onChange(`mailto:${e.target.value}`)}
|
||||||
|
placeholder="name@example.com"
|
||||||
|
style={inputStyle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{mode === 'url' && (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={value || ''}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
placeholder="https://example.com or /page"
|
||||||
|
style={inputStyle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parses a `border` shorthand ("2px solid #hex" / "none") back into the
|
||||||
|
{ width, style, color } shape BorderControl edits. */
|
||||||
|
function parseBorderShorthand(v: string | undefined): BorderValue {
|
||||||
|
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
||||||
|
const m = v.trim().match(/^(\S+)\s+(\S+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '#000000' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
function capitalize(s: string): string {
|
||||||
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- NAV / MENU / LOGO / FOOTER ---------- */
|
||||||
export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
|
const { pages } = usePages();
|
||||||
|
|
||||||
const links: any[] = nodeProps.links || [];
|
const links: any[] = nodeProps.links || [];
|
||||||
|
|
||||||
@@ -48,6 +181,20 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
});
|
});
|
||||||
}, [actions, selectedId]);
|
}, [actions, selectedId]);
|
||||||
|
|
||||||
|
/* F2: (re)populate the links array from the current pages list --
|
||||||
|
label = page name, href = '/' for the landing page else '/{slug}'.
|
||||||
|
Any existing CTA link (isCta: true) is preserved (appended after the
|
||||||
|
freshly-generated page links) rather than being wiped, matching the
|
||||||
|
legacy GrapesJS builder's "Sync with Pages" behavior. */
|
||||||
|
const syncWithPages = useCallback(() => {
|
||||||
|
actions.setProp(selectedId, (props: any) => {
|
||||||
|
const existing: any[] = props.links || [];
|
||||||
|
const ctaLinks = existing.filter((l) => l.isCta);
|
||||||
|
const pageLinks = pages.map((p, i) => ({ text: p.name, href: pageHref(p, i) }));
|
||||||
|
props.links = [...pageLinks, ...ctaLinks];
|
||||||
|
});
|
||||||
|
}, [actions, selectedId, pages]);
|
||||||
|
|
||||||
/* Detect standalone Logo vs Navbar/Menu */
|
/* Detect standalone Logo vs Navbar/Menu */
|
||||||
const isStandaloneLogo = nodeProps.type !== undefined && (nodeProps.type === 'text' || nodeProps.type === 'image') && nodeProps.logoText === undefined;
|
const isStandaloneLogo = nodeProps.type !== undefined && (nodeProps.type === 'text' || nodeProps.type === 'image') && nodeProps.logoText === undefined;
|
||||||
|
|
||||||
@@ -66,6 +213,15 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
);
|
);
|
||||||
const GAP_PRESETS = ['8px', '16px', '24px', '32px', '40px'].map((g) => ({ label: g, value: g }));
|
const GAP_PRESETS = ['8px', '16px', '24px', '32px', '40px'].map((g) => ({ label: g, value: g }));
|
||||||
|
|
||||||
|
/* Box-model / animation / visibility values, read off `style` (margin,
|
||||||
|
padding, border, boxShadow, opacity) or top-level props (animation,
|
||||||
|
hideOn*). This panel is only ever mounted for the 4 owned components
|
||||||
|
(Navbar/Menu/Logo/Footer), which all now carry these props (see each
|
||||||
|
component's .craft.props), so -- unlike the Links/Colors sections above,
|
||||||
|
which are shared across a genuinely disparate prop schema -- these
|
||||||
|
sections render unconditionally rather than gating on presence. */
|
||||||
|
const style = nodeProps.style || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Standalone Logo component settings */}
|
{/* Standalone Logo component settings */}
|
||||||
@@ -124,10 +280,11 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div style={sectionGap}>
|
<LinkPicker value={nodeProps.href || '/'} onChange={(v) => setProp('href', v)} />
|
||||||
<label style={labelStyle}>Link URL</label>
|
<label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: '#e4e4e7', cursor: 'pointer', marginTop: -8, marginBottom: 12 }}>
|
||||||
<input type="text" value={nodeProps.href || '/'} onChange={(e) => setProp('href', e.target.value)} placeholder="/" style={inputStyle} />
|
<input type="checkbox" checked={!!nodeProps.download} onChange={(e) => setProp('download', e.target.checked)} />
|
||||||
</div>
|
Download (link points at a file)
|
||||||
|
</label>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -145,17 +302,22 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{nodeProps.logoUrl !== undefined && (
|
{nodeProps.logoUrl !== undefined && (
|
||||||
<div style={sectionGap}>
|
<LinkPicker value={nodeProps.logoUrl || '/'} onChange={(v) => setProp('logoUrl', v)} />
|
||||||
<label style={labelStyle}>Logo Link URL</label>
|
|
||||||
<input type="text" value={nodeProps.logoUrl || ''} onChange={(e) => setProp('logoUrl', e.target.value)} placeholder="/" style={inputStyle} />
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Links (not shown for standalone Logo) */}
|
{/* Links (not shown for standalone Logo, or for components -- like
|
||||||
{!isStandaloneLogo && (
|
Footer -- that don't carry a `links` array at all). */}
|
||||||
|
{!isStandaloneLogo && nodeProps.links !== undefined && (
|
||||||
<CollapsibleSection title="Links">
|
<CollapsibleSection title="Links">
|
||||||
|
<button
|
||||||
|
onClick={syncWithPages}
|
||||||
|
title="Replace these links with one per page (preserves any CTA link)"
|
||||||
|
style={{ marginBottom: 8, width: '100%', padding: '6px', fontSize: 11, background: 'rgba(59,130,246,0.12)', color: '#93c5fd', border: '1px solid rgba(59,130,246,0.4)', borderRadius: 4, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6 }}
|
||||||
|
>
|
||||||
|
<i className="fa fa-refresh" /> Sync links with Pages
|
||||||
|
</button>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||||
{links.map((link, i) => (
|
{links.map((link, i) => (
|
||||||
<div key={i} style={{ background: '#1e1e22', borderRadius: 6, padding: 6, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
<div key={i} style={{ background: '#1e1e22', borderRadius: 6, padding: 6, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||||
@@ -165,7 +327,11 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
<i className="fa fa-times" />
|
<i className="fa fa-times" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" value={link.href || ''} onChange={(e) => updateLink(i, 'href', e.target.value)} placeholder="URL" style={{ ...smallInputStyle, color: '#71717a' }} />
|
<LinkPicker value={link.href || ''} onChange={(v) => updateLink(i, 'href', v)} />
|
||||||
|
<label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 10, color: '#a1a1aa', cursor: 'pointer', marginTop: -6 }}>
|
||||||
|
<input type="checkbox" checked={!!link.download} onChange={(e) => updateLink(i, 'download', e.target.checked)} />
|
||||||
|
Download (points at a file)
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -234,12 +400,61 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
|||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Style overrides */}
|
{/* Box model: margin + padding (per-side, via style.*). The old
|
||||||
|
single "Padding" preset row is folded into the Padding SpacingControl
|
||||||
|
below (still writes to style.padding when linked, matching the
|
||||||
|
previous behavior exactly). */}
|
||||||
<CollapsibleSection title="Spacing" defaultOpen={false}>
|
<CollapsibleSection title="Spacing" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{ top: style.marginTop, right: style.marginRight, bottom: style.marginBottom, left: style.marginLeft }}
|
||||||
|
onChange={(side, v) => setPropStyle(`margin${capitalize(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding"
|
||||||
|
value={{ top: style.paddingTop, right: style.paddingRight, bottom: style.paddingBottom, left: style.paddingLeft }}
|
||||||
|
onChange={(side, v) => setPropStyle(`padding${capitalize(side)}`, v)}
|
||||||
|
presets={SPACING_PRESETS}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Border & Effects: border, box-shadow, opacity */}
|
||||||
|
<CollapsibleSection title="Border & Effects" defaultOpen={false}>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderShorthand(style.border)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
<div className="guided-section">
|
<div className="guided-section">
|
||||||
<SectionLabel>Padding</SectionLabel>
|
<SectionLabel>Box Shadow</SectionLabel>
|
||||||
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={(nodeProps.style || {}).padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow || 'none'} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
||||||
</div>
|
</div>
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Opacity</label>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
value={style.opacity !== undefined ? Math.round(parseFloat(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, animationDelay: nodeProps.animationDelay }}
|
||||||
|
onChange={(v) => actions.setProp(selectedId, (p: any) => { p.animation = v.animation; p.animationDelay = v.animationDelay; })}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Responsive visibility */}
|
||||||
|
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
||||||
|
<VisibilityControl
|
||||||
|
value={{ hideOnDesktop: nodeProps.hideOnDesktop, hideOnTablet: nodeProps.hideOnTablet, hideOnMobile: nodeProps.hideOnMobile }}
|
||||||
|
onChange={(v) => actions.setProp(selectedId, (p: any) => { p.hideOnDesktop = v.hideOnDesktop; p.hideOnTablet = v.hideOnTablet; p.hideOnMobile = v.hideOnMobile; })}
|
||||||
|
/>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,340 @@
|
|||||||
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
|
import React from 'react';
|
||||||
|
import { createRoot, Root } from 'react-dom/client';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
import {
|
||||||
|
NumericUnitInput,
|
||||||
|
parseCssLength,
|
||||||
|
SizeControl,
|
||||||
|
AspectRatioControl,
|
||||||
|
parseAspectRatioInput,
|
||||||
|
FocalPointGrid,
|
||||||
|
FOCAL_POINTS,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
ANIMATIONS,
|
||||||
|
VisibilityControl,
|
||||||
|
} from './shared';
|
||||||
|
|
||||||
|
/* Same DOM-harness pattern as AssetPicker.test.tsx / ImageBlock.render.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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount() {
|
||||||
|
act(() => { root.unmount(); });
|
||||||
|
container.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function click(el: Element | null) {
|
||||||
|
if (!el) throw new Error('element not found');
|
||||||
|
act(() => { (el as HTMLElement).dispatchEvent(new MouseEvent('click', { bubbles: true })); });
|
||||||
|
}
|
||||||
|
|
||||||
|
function setValue(input: HTMLInputElement | HTMLSelectElement, value: string) {
|
||||||
|
const proto = input instanceof HTMLSelectElement ? window.HTMLSelectElement.prototype : window.HTMLInputElement.prototype;
|
||||||
|
const setter = Object.getOwnPropertyDescriptor(proto, 'value')!.set!;
|
||||||
|
setter.call(input, value);
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
function blur(el: Element) {
|
||||||
|
act(() => { el.dispatchEvent(new FocusEvent('blur', { bubbles: true })); el.dispatchEvent(new FocusEvent('focusout', { bubbles: true })); });
|
||||||
|
}
|
||||||
|
|
||||||
|
function q<T extends Element = Element>(testId: string): T | null {
|
||||||
|
return container.querySelector(`[data-testid="${testId}"]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- NumericUnitInput / parseCssLength ---------- */
|
||||||
|
describe('parseCssLength', () => {
|
||||||
|
test('parses "16px" into number 16 + unit px', () => {
|
||||||
|
expect(parseCssLength('16px')).toEqual({ num: '16', unit: 'px' });
|
||||||
|
});
|
||||||
|
test('parses "50%" into number 50 + unit %', () => {
|
||||||
|
expect(parseCssLength('50%', ['px', '%'])).toEqual({ num: '50', unit: '%' });
|
||||||
|
});
|
||||||
|
test('treats "auto" and "" as empty', () => {
|
||||||
|
expect(parseCssLength('auto')).toEqual({ num: '', unit: 'px' });
|
||||||
|
expect(parseCssLength('')).toEqual({ num: '', unit: 'px' });
|
||||||
|
expect(parseCssLength(undefined)).toEqual({ num: '', unit: 'px' });
|
||||||
|
});
|
||||||
|
test('falls back to the first configured unit for an unrecognized unit', () => {
|
||||||
|
expect(parseCssLength('16vh', ['px', '%'])).toEqual({ num: '16', unit: 'px' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('NumericUnitInput', () => {
|
||||||
|
test('renders the parsed number and unit from a "16px" value', () => {
|
||||||
|
render(<NumericUnitInput value="16px" onChange={vi.fn()} />);
|
||||||
|
expect(q<HTMLInputElement>('numeric-unit-number')!.value).toBe('16');
|
||||||
|
expect(q<HTMLSelectElement>('numeric-unit-unit')!.value).toBe('px');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing the number emits the recombined string', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<NumericUnitInput value="16px" onChange={onChange} />);
|
||||||
|
setValue(q<HTMLInputElement>('numeric-unit-number')!, '32');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('32px');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing the unit re-emits with the current number', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<NumericUnitInput value="16px" onChange={onChange} />);
|
||||||
|
setValue(q<HTMLSelectElement>('numeric-unit-unit')!, '%');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('16%');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clearing the number emits empty string, not "0px"', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<NumericUnitInput value="16px" onChange={onChange} />);
|
||||||
|
setValue(q<HTMLInputElement>('numeric-unit-number')!, '');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('omits the unit <select> when only one unit is configured', () => {
|
||||||
|
render(<NumericUnitInput value="1px" onChange={vi.fn()} units={['px']} />);
|
||||||
|
expect(q('numeric-unit-unit')).toBeNull();
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- SizeControl ---------- */
|
||||||
|
describe('SizeControl', () => {
|
||||||
|
test('clicking a preset button emits its value', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<SizeControl label="Width" value="" onChange={onChange} />);
|
||||||
|
const buttons = container.querySelectorAll('[data-testid="size-control"] .preset-btn');
|
||||||
|
const hundred = Array.from(buttons).find((b) => b.textContent === '100%')!;
|
||||||
|
click(hundred);
|
||||||
|
expect(onChange).toHaveBeenCalledWith('100%');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('custom numeric input emits a non-preset value', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<SizeControl label="Width" value="" onChange={onChange} />);
|
||||||
|
setValue(q<HTMLInputElement>('size-control-custom-number')!, '400');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('400px');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- AspectRatioControl / parseAspectRatioInput ---------- */
|
||||||
|
describe('parseAspectRatioInput', () => {
|
||||||
|
test('parses "16:9" into "16 / 9"', () => {
|
||||||
|
expect(parseAspectRatioInput('16:9')).toBe('16 / 9');
|
||||||
|
});
|
||||||
|
test('accepts "16/9" and "16x9" separators too', () => {
|
||||||
|
expect(parseAspectRatioInput('16/9')).toBe('16 / 9');
|
||||||
|
expect(parseAspectRatioInput('16x9')).toBe('16 / 9');
|
||||||
|
});
|
||||||
|
test('returns empty string for unparseable input', () => {
|
||||||
|
expect(parseAspectRatioInput('not-a-ratio')).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('AspectRatioControl', () => {
|
||||||
|
test('clicking the 16:9 preset emits "16 / 9"', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<AspectRatioControl value="" onChange={onChange} />);
|
||||||
|
const buttons = container.querySelectorAll('[data-testid="aspect-ratio-control"] .preset-btn');
|
||||||
|
const btn = Array.from(buttons).find((b) => b.textContent === '16:9')!;
|
||||||
|
click(btn);
|
||||||
|
expect(onChange).toHaveBeenCalledWith('16 / 9');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking Original emits empty string', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<AspectRatioControl value="1 / 1" onChange={onChange} />);
|
||||||
|
const buttons = container.querySelectorAll('[data-testid="aspect-ratio-control"] .preset-btn');
|
||||||
|
const btn = Array.from(buttons).find((b) => b.textContent === 'Original')!;
|
||||||
|
click(btn);
|
||||||
|
expect(onChange).toHaveBeenCalledWith('');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('typing a custom "16:9" and blurring emits "16 / 9"', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<AspectRatioControl value="" onChange={onChange} />);
|
||||||
|
const input = q<HTMLInputElement>('aspect-ratio-custom-input')!;
|
||||||
|
setValue(input, '16:9');
|
||||||
|
blur(input);
|
||||||
|
expect(onChange).toHaveBeenCalledWith('16 / 9');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- FocalPointGrid ---------- */
|
||||||
|
describe('FocalPointGrid', () => {
|
||||||
|
test('has 9 cells matching FOCAL_POINTS', () => {
|
||||||
|
render(<FocalPointGrid value="center" onChange={vi.fn()} />);
|
||||||
|
const cells = container.querySelectorAll('[data-testid="focal-point-grid"] button');
|
||||||
|
expect(cells.length).toBe(9);
|
||||||
|
expect(FOCAL_POINTS.length).toBe(9);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking a cell emits its object-position value', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<FocalPointGrid value="center" onChange={onChange} />);
|
||||||
|
click(q('focal-point-left-top'));
|
||||||
|
expect(onChange).toHaveBeenCalledWith('left top');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the active cell is visually highlighted (distinct background)', () => {
|
||||||
|
render(<FocalPointGrid value="right bottom" onChange={vi.fn()} />);
|
||||||
|
const active = q<HTMLButtonElement>('focal-point-right-bottom')!;
|
||||||
|
const inactive = q<HTMLButtonElement>('focal-point-center')!;
|
||||||
|
expect(active.style.background).not.toBe(inactive.style.background);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('defaults the highlight to center when value is empty', () => {
|
||||||
|
render(<FocalPointGrid value="" onChange={vi.fn()} />);
|
||||||
|
const center = q<HTMLButtonElement>('focal-point-center')!;
|
||||||
|
const other = q<HTMLButtonElement>('focal-point-left-top')!;
|
||||||
|
expect(center.style.background).not.toBe(other.style.background);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- SpacingControl ---------- */
|
||||||
|
describe('SpacingControl', () => {
|
||||||
|
test('linked mode: editing the shared field emits onChange for all 4 sides with the same value', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<SpacingControl label="Margin" value={{}} onChange={onChange} />);
|
||||||
|
setValue(q<HTMLInputElement>('spacing-linked-number')!, '16');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('top', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('right', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('bottom', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('left', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(4);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a preset fills all sides with the preset value', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<SpacingControl label="Padding" value={{}} onChange={onChange} />);
|
||||||
|
const buttons = container.querySelectorAll('[data-testid="spacing-control"] .preset-btn');
|
||||||
|
const medium = Array.from(buttons).find((b) => b.textContent === 'M')!;
|
||||||
|
click(medium);
|
||||||
|
expect(onChange).toHaveBeenCalledWith('top', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('left', '16px');
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(4);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unlinking lets each side emit independently', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<SpacingControl label="Margin" value={{ top: '4px', right: '4px', bottom: '4px', left: '4px' }} onChange={onChange} />);
|
||||||
|
click(q('spacing-link-toggle'));
|
||||||
|
setValue(q<HTMLInputElement>('spacing-top-number')!, '20');
|
||||||
|
expect(onChange).toHaveBeenCalledWith('top', '20px');
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(1);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- BorderControl ---------- */
|
||||||
|
describe('BorderControl', () => {
|
||||||
|
test('changing width/style/color merges into the full BorderValue object', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
const value = { width: '1px', style: 'solid', color: '#000000' };
|
||||||
|
render(<BorderControl value={value} onChange={onChange} />);
|
||||||
|
setValue(q<HTMLSelectElement>('border-style-select')!, 'dashed');
|
||||||
|
expect(onChange).toHaveBeenCalledWith({ width: '1px', style: 'dashed', color: '#000000' });
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('buildBorderShorthand builds a CSS border shorthand', () => {
|
||||||
|
expect(buildBorderShorthand({ width: '2px', style: 'solid', color: '#3b82f6' })).toBe('2px solid #3b82f6');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('buildBorderShorthand returns "none" when style is none or width is empty', () => {
|
||||||
|
expect(buildBorderShorthand({ width: '2px', style: 'none', color: '#000' })).toBe('none');
|
||||||
|
expect(buildBorderShorthand({ width: '', style: 'solid', color: '#000' })).toBe('none');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- AnimationControl ---------- */
|
||||||
|
describe('AnimationControl', () => {
|
||||||
|
test('ANIMATIONS matches the exact data-animation values html-export.ts supports', () => {
|
||||||
|
expect(ANIMATIONS.map((a) => a.value)).toEqual([
|
||||||
|
'none', 'fade-in', 'slide-up', 'slide-left', 'slide-right', 'zoom-in', 'bounce',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('selecting an animation emits { animation, animationDelay }', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<AnimationControl value={{ animation: 'none' }} onChange={onChange} />);
|
||||||
|
const buttons = container.querySelectorAll('[data-testid="animation-control"] .preset-btn');
|
||||||
|
const fadeIn = Array.from(buttons).find((b) => b.textContent === 'Fade In')!;
|
||||||
|
click(fadeIn);
|
||||||
|
expect(onChange).toHaveBeenCalledWith({ animation: 'fade-in', animationDelay: '0' });
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the delay input is hidden when animation is "none" and shown otherwise', () => {
|
||||||
|
render(<AnimationControl value={{ animation: 'none' }} onChange={vi.fn()} />);
|
||||||
|
expect(q('animation-delay-input')).toBeNull();
|
||||||
|
unmount();
|
||||||
|
|
||||||
|
render(<AnimationControl value={{ animation: 'bounce', animationDelay: '0.5' }} onChange={vi.fn()} />);
|
||||||
|
expect(q<HTMLInputElement>('animation-delay-input')!.value).toBe('0.5');
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing the delay emits the current animation with the new delay', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<AnimationControl value={{ animation: 'zoom-in', animationDelay: '0' }} onChange={onChange} />);
|
||||||
|
setValue(q<HTMLInputElement>('animation-delay-input')!, '0.3');
|
||||||
|
expect(onChange).toHaveBeenCalledWith({ animation: 'zoom-in', animationDelay: '0.3' });
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ---------- VisibilityControl ---------- */
|
||||||
|
describe('VisibilityControl', () => {
|
||||||
|
test('emits the exact hideOnDesktop/hideOnTablet/hideOnMobile prop names', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<VisibilityControl value={{}} onChange={onChange} />);
|
||||||
|
click(q('visibility-hideOnDesktop'));
|
||||||
|
expect(onChange).toHaveBeenCalledWith({ hideOnDesktop: true });
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toggling reflects existing true values back to false', () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(<VisibilityControl value={{ hideOnMobile: true }} onChange={onChange} />);
|
||||||
|
click(q('visibility-hideOnMobile'));
|
||||||
|
expect(onChange).toHaveBeenCalledWith({ hideOnMobile: false });
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checkboxes reflect the initial value', () => {
|
||||||
|
render(<VisibilityControl value={{ hideOnTablet: true }} onChange={vi.fn()} />);
|
||||||
|
expect(q<HTMLInputElement>('visibility-hideOnDesktop')!.checked).toBe(false);
|
||||||
|
expect(q<HTMLInputElement>('visibility-hideOnTablet')!.checked).toBe(true);
|
||||||
|
expect(q<HTMLInputElement>('visibility-hideOnMobile')!.checked).toBe(false);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,6 +2,10 @@ import React, { useState, useCallback, CSSProperties } from 'react';
|
|||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
import {
|
import {
|
||||||
GRADIENTS,
|
GRADIENTS,
|
||||||
|
SIZE_PRESETS,
|
||||||
|
ASPECT_RATIOS,
|
||||||
|
SPACING_PRESETS,
|
||||||
|
BORDER_STYLES,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import { uploadAsset } from '../../../utils/assets';
|
import { uploadAsset } from '../../../utils/assets';
|
||||||
|
|
||||||
@@ -372,3 +376,379 @@ export const ArrayPropEditor: React.FC<ArrayPropEditorProps> = ({ selectedId, pr
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* =========================================================================
|
||||||
|
ENH-Foundation: reusable StylePanel controls
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
Presentational (value + onChange) controls shared by upcoming feature
|
||||||
|
panels (size/spacing/border/typography/animation/visibility rollout).
|
||||||
|
Nothing below is wired into any feature panel yet -- that's the job of
|
||||||
|
the downstream feature branches. Each control's onChange API is
|
||||||
|
documented on its props interface; see
|
||||||
|
.superpowers/sdd/task-enh-foundation-report.md for the consolidated list.
|
||||||
|
========================================================================= */
|
||||||
|
|
||||||
|
/* ---------- NumericUnitInput ----------
|
||||||
|
A number field + unit dropdown that parses/holds a CSS length string
|
||||||
|
("16px", "50%", "auto", "") and calls onChange(nextString).
|
||||||
|
- Clearing the number field emits '' (not '0px') -- lets the consumer
|
||||||
|
treat '' as "unset/inherit" instead of forcing a 0 value.
|
||||||
|
- value === 'auto' or '' both display as a blank number field (with the
|
||||||
|
`placeholder` -- default "auto" -- shown as a hint).
|
||||||
|
- Changing the unit re-emits with the current number and the new unit;
|
||||||
|
if the number is blank, changing the unit is a no-op (still emits '').
|
||||||
|
- `units` is configurable (default ['px','%']); the unit <select> is
|
||||||
|
omitted entirely when only one unit is passed. */
|
||||||
|
export function parseCssLength(value: string | undefined, units: string[] = ['px', '%']): { num: string; unit: string } {
|
||||||
|
if (!value || value === 'auto') return { num: '', unit: units[0] };
|
||||||
|
const m = String(value).trim().match(/^(-?\d*\.?\d+)\s*([a-zA-Z%]*)$/);
|
||||||
|
if (!m) return { num: '', unit: units[0] };
|
||||||
|
const unit = m[2] || units[0];
|
||||||
|
return { num: m[1], unit: units.includes(unit) ? unit : units[0] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NumericUnitInputProps {
|
||||||
|
/** CSS length string, e.g. "16px" / "50%" / "auto" / "". */
|
||||||
|
value: string;
|
||||||
|
/** Called with the recombined string, e.g. "16px". Called with '' when the
|
||||||
|
* number field is cleared. */
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
/** Allowed unit list; default ['px', '%']. Unit <select> is hidden when
|
||||||
|
* this has length 1. */
|
||||||
|
units?: string[];
|
||||||
|
min?: number;
|
||||||
|
max?: number;
|
||||||
|
step?: number;
|
||||||
|
placeholder?: string;
|
||||||
|
/** Base for the data-testid attrs (`${testId}`, `${testId}-number`,
|
||||||
|
* `${testId}-unit`); default 'numeric-unit'. */
|
||||||
|
testId?: string;
|
||||||
|
}
|
||||||
|
export const NumericUnitInput: React.FC<NumericUnitInputProps> = ({
|
||||||
|
value, onChange, units = ['px', '%'], min, max, step, placeholder = 'auto', testId = 'numeric-unit',
|
||||||
|
}) => {
|
||||||
|
const { num, unit } = parseCssLength(value, units);
|
||||||
|
const emit = (nextNum: string, nextUnit: string) => {
|
||||||
|
if (nextNum === '') { onChange(''); return; }
|
||||||
|
onChange(`${nextNum}${nextUnit}`);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', gap: 4 }} data-testid={testId}>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
data-testid={`${testId}-number`}
|
||||||
|
value={num}
|
||||||
|
min={min}
|
||||||
|
max={max}
|
||||||
|
step={step}
|
||||||
|
placeholder={placeholder}
|
||||||
|
onChange={(e) => emit(e.target.value, unit)}
|
||||||
|
style={{ ...inputStyle, flex: 1 }}
|
||||||
|
/>
|
||||||
|
{units.length > 1 && (
|
||||||
|
<select
|
||||||
|
data-testid={`${testId}-unit`}
|
||||||
|
value={unit}
|
||||||
|
onChange={(e) => emit(num, e.target.value)}
|
||||||
|
style={{ ...inputStyle, width: 60, flex: 'none' }}
|
||||||
|
>
|
||||||
|
{units.map((u) => <option key={u} value={u}>{u}</option>)}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------- SizeControl ----------
|
||||||
|
Width (or height) editor: preset buttons (25/50/75/100%, Auto, Full) +
|
||||||
|
a custom NumericUnitInput. One dimension per instance -- render two
|
||||||
|
(label="Width" / label="Height") for components needing both, e.g.
|
||||||
|
ImageBlock / VideoBlock sizing. */
|
||||||
|
export interface SizeControlProps {
|
||||||
|
label: string;
|
||||||
|
/** CSS value for this one dimension, e.g. "100%" / "400px" / "auto" / "". */
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
presets?: { label: string; value: string }[];
|
||||||
|
units?: string[];
|
||||||
|
}
|
||||||
|
export const SizeControl: React.FC<SizeControlProps> = ({ label, value, onChange, presets = SIZE_PRESETS, units = ['px', '%'] }) => (
|
||||||
|
<div className="guided-section" data-testid="size-control">
|
||||||
|
<SectionLabel>{label}</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={presets} activeValue={value} onSelect={onChange} />
|
||||||
|
<div style={{ marginTop: 6 }}>
|
||||||
|
<NumericUnitInput
|
||||||
|
value={presets.some((p) => p.value === value) ? '' : value}
|
||||||
|
onChange={onChange}
|
||||||
|
units={units}
|
||||||
|
testId="size-control-custom"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ---------- AspectRatioControl ----------
|
||||||
|
Preset buttons + a custom "W:H" text entry. Emits a CSS `aspect-ratio`
|
||||||
|
value, e.g. "16 / 9". 'Original' emits ''. Custom entry accepts
|
||||||
|
"16:9" / "16/9" / "16x9" and is parsed on blur or Enter. */
|
||||||
|
export function parseAspectRatioInput(raw: string): string {
|
||||||
|
const m = raw.trim().match(/^(\d+(?:\.\d+)?)\s*[:xX/]\s*(\d+(?:\.\d+)?)$/);
|
||||||
|
if (!m) return '';
|
||||||
|
return `${m[1]} / ${m[2]}`;
|
||||||
|
}
|
||||||
|
function formatAspectRatioForInput(value: string): string {
|
||||||
|
const m = value.match(/^(\d+(?:\.\d+)?)\s*\/\s*(\d+(?:\.\d+)?)$/);
|
||||||
|
return m ? `${m[1]}:${m[2]}` : '';
|
||||||
|
}
|
||||||
|
export interface AspectRatioControlProps {
|
||||||
|
/** CSS `aspect-ratio` value, e.g. "16 / 9", or '' for Original/unset. */
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
presets?: { label: string; value: string }[];
|
||||||
|
}
|
||||||
|
export const AspectRatioControl: React.FC<AspectRatioControlProps> = ({ value, onChange, presets = ASPECT_RATIOS }) => {
|
||||||
|
const [custom, setCustom] = useState(() => formatAspectRatioForInput(value));
|
||||||
|
|
||||||
|
const applyCustom = () => onChange(parseAspectRatioInput(custom));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="guided-section" data-testid="aspect-ratio-control">
|
||||||
|
<SectionLabel>Aspect Ratio</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={presets} activeValue={value} onSelect={(v) => { onChange(v); setCustom(''); }} />
|
||||||
|
<div style={{ marginTop: 6 }}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
data-testid="aspect-ratio-custom-input"
|
||||||
|
value={custom}
|
||||||
|
placeholder="W:H e.g. 16:9"
|
||||||
|
onChange={(e) => setCustom(e.target.value)}
|
||||||
|
onBlur={applyCustom}
|
||||||
|
onKeyDown={(e) => { if (e.key === 'Enter') applyCustom(); }}
|
||||||
|
style={{ ...inputStyle }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------- FocalPointGrid ----------
|
||||||
|
3x3 grid of buttons mapping to CSS `object-position` keyword pairs.
|
||||||
|
Used for image crop framing (object-position on an ImageBlock/VideoBlock
|
||||||
|
with object-fit: cover). Highlights the active cell; defaults the
|
||||||
|
highlight to 'center' when value is empty. */
|
||||||
|
export const FOCAL_POINTS: { label: string; value: string }[] = [
|
||||||
|
{ label: '↖', value: 'left top' }, { label: '↑', value: 'center top' }, { label: '↗', value: 'right top' },
|
||||||
|
{ label: '←', value: 'left center' }, { label: '•', value: 'center' }, { label: '→', value: 'right center' },
|
||||||
|
{ label: '↙', value: 'left bottom' }, { label: '↓', value: 'center bottom' }, { label: '↘', value: 'right bottom' },
|
||||||
|
];
|
||||||
|
export interface FocalPointGridProps {
|
||||||
|
/** CSS `object-position` value, e.g. "center" / "left top". */
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}
|
||||||
|
export const FocalPointGrid: React.FC<FocalPointGridProps> = ({ value, onChange }) => {
|
||||||
|
const active = value || 'center';
|
||||||
|
return (
|
||||||
|
<div className="guided-section" data-testid="focal-point-grid">
|
||||||
|
<SectionLabel>Focal Point</SectionLabel>
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 4, width: 96 }}>
|
||||||
|
{FOCAL_POINTS.map((p) => (
|
||||||
|
<button
|
||||||
|
key={p.value}
|
||||||
|
data-testid={`focal-point-${p.value.replace(/\s+/g, '-')}`}
|
||||||
|
onClick={() => onChange(p.value)}
|
||||||
|
title={p.value}
|
||||||
|
style={{
|
||||||
|
aspectRatio: '1', border: '1px solid #3f3f46', borderRadius: 4, cursor: 'pointer',
|
||||||
|
background: active === p.value ? '#3b82f6' : '#27272a',
|
||||||
|
color: active === p.value ? '#fff' : '#71717a', fontSize: 12,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{p.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------- SpacingControl ----------
|
||||||
|
Margin OR padding, per-side, with a link/unlink toggle.
|
||||||
|
API: onChange(side, value) -- called once per side. In linked mode
|
||||||
|
(default), editing the single shared field or clicking a preset calls
|
||||||
|
onChange for all four sides ('top','right','bottom','left') with the
|
||||||
|
same value so the consumer can setPropStyle each side independently
|
||||||
|
(e.g. marginTop/marginRight/marginBottom/marginLeft). In unlinked mode
|
||||||
|
each side's NumericUnitInput calls onChange for just that side. */
|
||||||
|
export type SpacingSide = 'top' | 'right' | 'bottom' | 'left';
|
||||||
|
export interface SpacingSideValues { top?: string; right?: string; bottom?: string; left?: string; }
|
||||||
|
const SPACING_SIDES: SpacingSide[] = ['top', 'right', 'bottom', 'left'];
|
||||||
|
export interface SpacingControlProps {
|
||||||
|
label: string;
|
||||||
|
value: SpacingSideValues;
|
||||||
|
/** Called per-side. Linked edits/presets call this once for each of the
|
||||||
|
* 4 sides (in top/right/bottom/left order) with the same value. */
|
||||||
|
onChange: (side: SpacingSide, value: string) => void;
|
||||||
|
presets?: { label: string; value: string }[];
|
||||||
|
units?: string[];
|
||||||
|
}
|
||||||
|
export const SpacingControl: React.FC<SpacingControlProps> = ({ label, value, onChange, presets = SPACING_PRESETS, units = ['px', '%', 'em', 'rem'] }) => {
|
||||||
|
const [linked, setLinked] = useState(true);
|
||||||
|
|
||||||
|
const applyToAllSides = (v: string) => SPACING_SIDES.forEach((s) => onChange(s, v));
|
||||||
|
const linkedValue = value.top ?? '';
|
||||||
|
const isAllEqual = SPACING_SIDES.every((s) => (value[s] ?? '') === linkedValue);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="guided-section" data-testid="spacing-control">
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
|
<SectionLabel>{label}</SectionLabel>
|
||||||
|
<button
|
||||||
|
data-testid="spacing-link-toggle"
|
||||||
|
onClick={() => setLinked(!linked)}
|
||||||
|
title={linked ? 'Unlink sides' : 'Link sides'}
|
||||||
|
style={{ background: 'none', border: 'none', color: linked ? '#3b82f6' : '#71717a', cursor: 'pointer', padding: 2 }}
|
||||||
|
>
|
||||||
|
<i className={`fa fa-link${linked ? '' : '-slash'}`} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<PresetButtonGrid presets={presets} activeValue={isAllEqual ? linkedValue : undefined} onSelect={applyToAllSides} />
|
||||||
|
{linked ? (
|
||||||
|
<div style={{ marginTop: 6 }}>
|
||||||
|
<NumericUnitInput value={linkedValue} onChange={applyToAllSides} units={units} testId="spacing-linked" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, marginTop: 6 }}>
|
||||||
|
{SPACING_SIDES.map((s) => (
|
||||||
|
<div key={s}>
|
||||||
|
<label style={{ ...labelStyle, fontSize: 9 }}>{s}</label>
|
||||||
|
<NumericUnitInput value={value[s] ?? ''} onChange={(v) => onChange(s, v)} units={units} testId={`spacing-${s}`} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------- BorderControl ----------
|
||||||
|
Width (px) + style (none/solid/dashed/dotted) + color. Single onChange
|
||||||
|
receives the merged { width, style, color } object so the consumer can
|
||||||
|
either setProp each part or build a shorthand via buildBorderShorthand()
|
||||||
|
(returns 'none' when width is falsy or style is 'none'). */
|
||||||
|
export interface BorderValue { width: string; style: string; color: string; }
|
||||||
|
export interface BorderControlProps {
|
||||||
|
value: BorderValue;
|
||||||
|
onChange: (value: BorderValue) => void;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
export const BorderControl: React.FC<BorderControlProps> = ({ value, onChange, label = 'Border' }) => {
|
||||||
|
const set = (patch: Partial<BorderValue>) => onChange({ ...value, ...patch });
|
||||||
|
return (
|
||||||
|
<div className="guided-section" data-testid="border-control">
|
||||||
|
<SectionLabel>{label}</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', gap: 6, marginBottom: 6 }}>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<NumericUnitInput value={value.width} onChange={(v) => set({ width: v })} units={['px']} placeholder="0" testId="border-width" />
|
||||||
|
</div>
|
||||||
|
<select
|
||||||
|
data-testid="border-style-select"
|
||||||
|
value={value.style}
|
||||||
|
onChange={(e) => set({ style: e.target.value })}
|
||||||
|
style={{ ...inputStyle, flex: 1 }}
|
||||||
|
>
|
||||||
|
{BORDER_STYLES.map((s) => <option key={s.value} value={s.value}>{s.label}</option>)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<ColorPickerField label="Border Color" value={value.color} onChange={(v) => set({ color: v })} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export function buildBorderShorthand(value: BorderValue): string {
|
||||||
|
if (!value.width || !value.style || value.style === 'none') return 'none';
|
||||||
|
return `${value.width} ${value.style} ${value.color || '#000000'}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- AnimationControl ----------
|
||||||
|
"Entrance animation" picker + optional delay. Emits the EXACT prop names
|
||||||
|
the export machinery already consumes (verified against buildDataAttrs()
|
||||||
|
in src/utils/html-export.ts): `animation` and `animationDelay`.
|
||||||
|
NOTE: the export supports fade-in / slide-up / slide-left / slide-right /
|
||||||
|
zoom-in / bounce (no "slide-down" -- html-export.ts has no such variant;
|
||||||
|
slide-left/slide-right exist instead), so ANIMATIONS reflects that exact
|
||||||
|
set rather than guessing. animationDelay is a plain seconds string (e.g.
|
||||||
|
"0.3") -- html-export.ts's inline script assigns it straight to
|
||||||
|
el.style.animationDelay, so consumers should suffix/accept a unit-bearing
|
||||||
|
string like "0.3s" if that's what they choose to store; this control
|
||||||
|
stores/edits the raw numeric string and leaves unit formatting to the
|
||||||
|
caller (kept as the simplest contract; see report for the exact
|
||||||
|
behavior verified against html-export.ts). */
|
||||||
|
export const ANIMATIONS: { label: string; value: string }[] = [
|
||||||
|
{ label: 'None', value: 'none' },
|
||||||
|
{ label: 'Fade In', value: 'fade-in' },
|
||||||
|
{ label: 'Slide Up', value: 'slide-up' },
|
||||||
|
{ label: 'Slide Left', value: 'slide-left' },
|
||||||
|
{ label: 'Slide Right', value: 'slide-right' },
|
||||||
|
{ label: 'Zoom In', value: 'zoom-in' },
|
||||||
|
{ label: 'Bounce', value: 'bounce' },
|
||||||
|
];
|
||||||
|
export interface AnimationValue { animation: string; animationDelay?: string; }
|
||||||
|
export interface AnimationControlProps {
|
||||||
|
value: AnimationValue;
|
||||||
|
onChange: (value: AnimationValue) => void;
|
||||||
|
}
|
||||||
|
export const AnimationControl: React.FC<AnimationControlProps> = ({ value, onChange }) => {
|
||||||
|
const animation = value.animation || 'none';
|
||||||
|
const animationDelay = value.animationDelay ?? '0';
|
||||||
|
return (
|
||||||
|
<div className="guided-section" data-testid="animation-control">
|
||||||
|
<SectionLabel>Entrance Animation</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={ANIMATIONS} activeValue={animation} onSelect={(v) => onChange({ animation: v, animationDelay })} />
|
||||||
|
{animation !== 'none' && (
|
||||||
|
<div style={{ marginTop: 6 }}>
|
||||||
|
<label style={labelStyle}>Delay (seconds)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
data-testid="animation-delay-input"
|
||||||
|
min={0}
|
||||||
|
step={0.1}
|
||||||
|
value={animationDelay}
|
||||||
|
onChange={(e) => onChange({ animation, animationDelay: e.target.value })}
|
||||||
|
style={inputStyle}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------- VisibilityControl ----------
|
||||||
|
Hide on Desktop / Tablet / Mobile toggles. Emits the EXACT prop names
|
||||||
|
the export machinery already consumes (verified against buildDataAttrs()
|
||||||
|
in src/utils/html-export.ts): `hideOnDesktop`, `hideOnTablet`,
|
||||||
|
`hideOnMobile` (each rendered as data-hide-desktop/tablet/mobile when
|
||||||
|
truthy). Single onChange receives the merged object. */
|
||||||
|
export interface VisibilityValue { hideOnDesktop?: boolean; hideOnTablet?: boolean; hideOnMobile?: boolean; }
|
||||||
|
export interface VisibilityControlProps {
|
||||||
|
value: VisibilityValue;
|
||||||
|
onChange: (value: VisibilityValue) => void;
|
||||||
|
}
|
||||||
|
const VISIBILITY_KEYS: (keyof VisibilityValue)[] = ['hideOnDesktop', 'hideOnTablet', 'hideOnMobile'];
|
||||||
|
export const VisibilityControl: React.FC<VisibilityControlProps> = ({ value, onChange }) => (
|
||||||
|
<div className="guided-section" data-testid="visibility-control">
|
||||||
|
<SectionLabel>Visibility</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||||
|
{VISIBILITY_KEYS.map((key) => (
|
||||||
|
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: '#e4e4e7', cursor: 'pointer' }}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
data-testid={`visibility-${key}`}
|
||||||
|
checked={!!value[key]}
|
||||||
|
onChange={() => onChange({ ...value, [key]: !value[key] })}
|
||||||
|
/>
|
||||||
|
Hide on {key.replace('hideOn', '')}
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user