Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bf525c600 | ||
|
|
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",
|
||||||
|
|||||||
@@ -44,3 +44,29 @@ describe('Icon.toHtml XSS hardening', () => {
|
|||||||
expect(html).not.toMatch(/"\s+onclick="/);
|
expect(html).not.toMatch(/"\s+onclick="/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Icon.toHtml bgShape/bgColor/bgSize rendering (built but, until this panel update, unexposed)', () => {
|
||||||
|
test('bgShape="circle" + bgColor render a colored 50%-radius background box', () => {
|
||||||
|
const { html } = toHtml({ icon: 'fa-star', bgShape: 'circle', bgColor: '#3b82f6', bgSize: '64px' }, '');
|
||||||
|
expect(html).toContain('background-color:#3b82f6');
|
||||||
|
expect(html).toContain('border-radius:50%');
|
||||||
|
expect(html).toContain('width:64px');
|
||||||
|
expect(html).toContain('height:64px');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('bgShape="none" (default) renders the bare icon with no background wrapper', () => {
|
||||||
|
const { html } = toHtml({ icon: 'fa-star' }, '');
|
||||||
|
expect(html).not.toContain('background-color');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Icon.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (Icon as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ interface IconProps {
|
|||||||
bgSize?: string;
|
bgSize?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBgBorderRadius(shape: string): string {
|
function getBgBorderRadius(shape: string): string {
|
||||||
@@ -96,6 +101,11 @@ Icon.craft = {
|
|||||||
bgSize: '56px',
|
bgSize: '56px',
|
||||||
link: '',
|
link: '',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -51,3 +51,43 @@ describe('SocialLinks.toHtml XSS hardening (iconSize/iconColor/iconBgColor/gap i
|
|||||||
expect(html).not.toContain('javascript:alert(1)');
|
expect(html).not.toContain('javascript:alert(1)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('SocialLinks.toHtml iconShape/gap emission (previously built but unexposed in SocialStylePanel)', () => {
|
||||||
|
test('iconShape="circle" emits a 50% border-radius on the wrapping <a>', () => {
|
||||||
|
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'circle' }, '');
|
||||||
|
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:50%[^"]*"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('iconShape="square" emits border-radius:0', () => {
|
||||||
|
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'square' }, '');
|
||||||
|
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:0[^"]*"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('iconShape="rounded" emits a 6px border-radius', () => {
|
||||||
|
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'rounded' }, '');
|
||||||
|
expect(html).toMatch(/<a[^>]*style="[^"]*border-radius:6px[^"]*"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('iconShape="none" omits the background box entirely (transparent bg, no fixed box size)', () => {
|
||||||
|
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], iconShape: 'none' }, '');
|
||||||
|
const aTag = html.match(/<a[^>]*>/)![0];
|
||||||
|
expect(aTag).toContain('background-color:transparent');
|
||||||
|
expect(aTag).not.toContain('border-radius');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gap emits on the wrapper <div> style', () => {
|
||||||
|
const { html } = toHtml({ links: [{ platform: 'facebook', url: '#' }], gap: '24px' }, '');
|
||||||
|
expect(html).toMatch(/<div[^>]*style="[^"]*gap:24px[^"]*"/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SocialLinks.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (SocialLinks as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ interface SocialLinksProps {
|
|||||||
gap?: string;
|
gap?: string;
|
||||||
alignment?: 'left' | 'center' | 'right';
|
alignment?: 'left' | 'center' | 'right';
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformIcons: Record<string, string> = {
|
const platformIcons: Record<string, string> = {
|
||||||
@@ -151,6 +156,11 @@ SocialLinks.craft = {
|
|||||||
gap: '10px',
|
gap: '10px',
|
||||||
alignment: 'center',
|
alignment: 'center',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -75,3 +75,14 @@ describe('StarRating.toHtml XSS hardening (rating/maxStars into aria-label, F2.2
|
|||||||
expect(html).toMatch(/<span role="img" aria-label="Rating: 4\.5 out of 5"/);
|
expect(html).toMatch(/<span role="img" aria-label="Rating: 4\.5 out of 5"/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('StarRating.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (StarRating as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ interface StarRatingProps {
|
|||||||
filledColor?: string;
|
filledColor?: string;
|
||||||
emptyColor?: string;
|
emptyColor?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StarRating: UserComponent<StarRatingProps> = ({
|
export const StarRating: UserComponent<StarRatingProps> = ({
|
||||||
@@ -87,6 +92,11 @@ StarRating.craft = {
|
|||||||
filledColor: '#f59e0b',
|
filledColor: '#f59e0b',
|
||||||
emptyColor: '#d1d5db',
|
emptyColor: '#d1d5db',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { Accordion } from './Accordion';
|
||||||
|
|
||||||
|
const toHtml = (Accordion as any).toHtml;
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{ title: 'Q1', content: 'A1', isOpen: true },
|
||||||
|
{ title: 'Q2', content: 'A2', isOpen: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('Accordion.toHtml basic export', () => {
|
||||||
|
test('renders a <details> per item with the open attribute honored', () => {
|
||||||
|
const { html } = toHtml({ items }, '');
|
||||||
|
const detailsBlocks = html.match(/<details[^>]*>/g) || [];
|
||||||
|
expect(detailsBlocks.length).toBe(2);
|
||||||
|
expect(detailsBlocks[0]).toContain(' open');
|
||||||
|
expect(detailsBlocks[1]).not.toContain(' open');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('headerBg/headerColor/contentBg/borderColor emit into the panel styles', () => {
|
||||||
|
const { html } = toHtml({ items, headerBg: '#111111', headerColor: '#222222', contentBg: '#333333', borderColor: '#444444' }, '');
|
||||||
|
expect(html).toContain('#111111');
|
||||||
|
expect(html).toContain('#222222');
|
||||||
|
expect(html).toContain('#333333');
|
||||||
|
expect(html).toContain('#444444');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Accordion.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (Accordion as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -17,6 +17,11 @@ interface AccordionProps {
|
|||||||
contentBg?: string;
|
contentBg?: string;
|
||||||
borderColor?: string;
|
borderColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultItems: AccordionItem[] = [
|
const defaultItems: AccordionItem[] = [
|
||||||
@@ -135,6 +140,11 @@ Accordion.craft = {
|
|||||||
contentBg: '#ffffff',
|
contentBg: '#ffffff',
|
||||||
borderColor: '#e2e8f0',
|
borderColor: '#e2e8f0',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { CTASection } from './CTASection';
|
||||||
|
|
||||||
|
const toHtml = (CTASection as any).toHtml;
|
||||||
|
|
||||||
|
describe('CTASection.toHtml basic export', () => {
|
||||||
|
test('renders heading, description, and CTA buttons', () => {
|
||||||
|
const { html } = toHtml({ heading: 'Hi', description: 'Sub', ctas: [{ text: 'Go', href: '#', variant: 'primary' }] }, '');
|
||||||
|
expect(html).toContain('Hi');
|
||||||
|
expect(html).toContain('Sub');
|
||||||
|
expect(html).toContain('Go');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('box-model style props (margin/padding/border/boxShadow/opacity) flow through to the section style=""', () => {
|
||||||
|
const { html } = toHtml({
|
||||||
|
heading: 'Hi',
|
||||||
|
description: 'Sub',
|
||||||
|
style: { marginTop: '10px', paddingLeft: '5px', border: '1px solid #000', boxShadow: '0 1px 2px rgba(0,0,0,0.1)', opacity: '0.5' },
|
||||||
|
}, '');
|
||||||
|
expect(html).toContain('margin-top:10px');
|
||||||
|
expect(html).toContain('padding-left:5px');
|
||||||
|
expect(html).toContain('border:1px solid #000');
|
||||||
|
expect(html).toContain('box-shadow:0 1px 2px rgba(0,0,0,0.1)');
|
||||||
|
expect(html).toContain('opacity:0.5');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('CTASection.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (CTASection as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,6 +14,11 @@ interface CTASectionProps {
|
|||||||
gradient?: string;
|
gradient?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||||
@@ -83,6 +88,11 @@ CTASection.craft = {
|
|||||||
gradient: defaultGradient,
|
gradient: defaultGradient,
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { CallToAction } from './CallToAction';
|
||||||
|
|
||||||
|
const toHtml = (CallToAction as any).toHtml;
|
||||||
|
|
||||||
|
describe('CallToAction.toHtml basic export', () => {
|
||||||
|
test('renders heading, description, and CTA buttons', () => {
|
||||||
|
const { html } = toHtml({ heading: 'Hi', description: 'Sub', ctas: [{ text: 'Go', href: '#', variant: 'primary' }] }, '');
|
||||||
|
expect(html).toContain('Hi');
|
||||||
|
expect(html).toContain('Sub');
|
||||||
|
expect(html).toContain('Go');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('box-model style props (margin/padding/border/boxShadow/opacity) flow through to the section style=""', () => {
|
||||||
|
const { html } = toHtml({
|
||||||
|
heading: 'Hi',
|
||||||
|
description: 'Sub',
|
||||||
|
style: { marginBottom: '12px', paddingRight: '6px', border: '2px dashed #333', boxShadow: '0 4px 8px rgba(0,0,0,0.12)', opacity: '0.75' },
|
||||||
|
}, '');
|
||||||
|
expect(html).toContain('margin-bottom:12px');
|
||||||
|
expect(html).toContain('padding-right:6px');
|
||||||
|
expect(html).toContain('border:2px dashed #333');
|
||||||
|
expect(html).toContain('box-shadow:0 4px 8px rgba(0,0,0,0.12)');
|
||||||
|
expect(html).toContain('opacity:0.75');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('CallToAction.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (CallToAction as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -21,6 +21,11 @@ interface CallToActionProps {
|
|||||||
buttonColor?: string;
|
buttonColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
||||||
@@ -131,6 +136,11 @@ CallToAction.craft = {
|
|||||||
textColor: '#ffffff',
|
textColor: '#ffffff',
|
||||||
buttonColor: '#ffffff',
|
buttonColor: '#ffffff',
|
||||||
style: {},
|
style: {},
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -62,3 +62,14 @@ describe('Countdown.toHtml script nit: ticking interval stops at zero', () => {
|
|||||||
expect(html).toMatch(/if\s*\(\s*target\s*-\s*Date\.now\(\)\s*>\s*0\s*\)\s*\{/);
|
expect(html).toMatch(/if\s*\(\s*target\s*-\s*Date\.now\(\)\s*>\s*0\s*\)\s*\{/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Countdown.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (Countdown as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ interface CountdownProps {
|
|||||||
labelColor?: string;
|
labelColor?: string;
|
||||||
bgColor?: string;
|
bgColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TimeLeft {
|
interface TimeLeft {
|
||||||
@@ -139,6 +144,11 @@ Countdown.craft = {
|
|||||||
labelColor: 'rgba(255,255,255,0.7)',
|
labelColor: 'rgba(255,255,255,0.7)',
|
||||||
bgColor: '#18181b',
|
bgColor: '#18181b',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -21,3 +21,14 @@ describe('FeaturesGrid.toHtml image sink uses safeImageUrl (data:image/svg+xml a
|
|||||||
expect(html).toMatch(/<a href=""/);
|
expect(html).toMatch(/<a href=""/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('FeaturesGrid.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (FeaturesGrid as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ interface FeaturesGridProps {
|
|||||||
features?: FeatureItem[];
|
features?: FeatureItem[];
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys image/imageAlt/buttonText/buttonUrl are present (blank) on the defaults so
|
// Keys image/imageAlt/buttonText/buttonUrl are present (blank) on the defaults so
|
||||||
@@ -98,6 +103,11 @@ FeaturesGrid.craft = {
|
|||||||
features: defaultFeatures,
|
features: defaultFeatures,
|
||||||
style: { backgroundColor: '#ffffff' },
|
style: { backgroundColor: '#ffffff' },
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -73,3 +73,14 @@ describe('NumberCounter.toHtml counter.number is NOT runtime-type-checked -- mus
|
|||||||
expect(html).toContain('data-target="150"');
|
expect(html).toContain('data-target="150"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('NumberCounter.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (NumberCounter as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ interface NumberCounterProps {
|
|||||||
labelColor?: string;
|
labelColor?: string;
|
||||||
numberSize?: string;
|
numberSize?: string;
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCounters: Counter[] = [
|
const defaultCounters: Counter[] = [
|
||||||
@@ -99,6 +104,11 @@ NumberCounter.craft = {
|
|||||||
labelColor: '#6b7280',
|
labelColor: '#6b7280',
|
||||||
numberSize: '48px',
|
numberSize: '48px',
|
||||||
style: { backgroundColor: '#ffffff' },
|
style: { backgroundColor: '#ffffff' },
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { PricingTable } from './PricingTable';
|
||||||
|
|
||||||
|
const toHtml = (PricingTable as any).toHtml;
|
||||||
|
|
||||||
|
const plans = [
|
||||||
|
{ name: 'Basic', price: '$9', period: '/month', features: ['Feature A'], buttonText: 'Buy', buttonHref: '#', isFeatured: false },
|
||||||
|
{ name: 'Pro', price: '$29', period: '/month', features: ['Feature B'], buttonText: 'Buy', buttonHref: '#', isFeatured: true },
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('PricingTable.toHtml regular-card color overrides (previously hard-coded, now real props)', () => {
|
||||||
|
test('cardBg emits as the non-featured card background', () => {
|
||||||
|
const { html } = toHtml({ plans, cardBg: '#f0f0f0' }, '');
|
||||||
|
expect(html).toContain('background-color:#f0f0f0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('textColor emits as the non-featured heading/price color', () => {
|
||||||
|
const { html } = toHtml({ plans, textColor: '#123456' }, '');
|
||||||
|
expect(html).toContain('color:#123456');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('subColor emits as the non-featured period text color', () => {
|
||||||
|
const { html } = toHtml({ plans, subColor: '#abcdef' }, '');
|
||||||
|
expect(html).toContain('color:#abcdef');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('featColor emits as the non-featured feature list text color', () => {
|
||||||
|
const { html } = toHtml({ plans, featColor: '#334455' }, '');
|
||||||
|
expect(html).toContain('color:#334455');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checkColor emits as the non-featured bullet color', () => {
|
||||||
|
const { html } = toHtml({ plans, checkColor: '#00ff00' }, '');
|
||||||
|
expect(html).toContain('color:#00ff00');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('btnBg/btnColor emit as the non-featured button colors', () => {
|
||||||
|
const { html } = toHtml({ plans, btnBg: '#111111', btnColor: '#eeeeee' }, '');
|
||||||
|
expect(html).toContain('background-color:#111111');
|
||||||
|
expect(html).toContain('color:#eeeeee');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unset overrides fall back to the exact prior literals (backward compatible)', () => {
|
||||||
|
const { html } = toHtml({ plans }, '');
|
||||||
|
// Regular (non-featured) card literals unchanged from before these props existed.
|
||||||
|
expect(html).toContain('background-color:#ffffff');
|
||||||
|
expect(html).toContain('color:#18181b');
|
||||||
|
expect(html).toContain('color:#64748b');
|
||||||
|
expect(html).toContain('color:#4b5563');
|
||||||
|
expect(html).toContain('color:#10b981');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unset btnBg falls back to featuredBg (original derivation)', () => {
|
||||||
|
const { html } = toHtml({ plans, featuredBg: '#654321' }, '');
|
||||||
|
expect(html).toContain('background-color:#654321');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('PricingTable.toHtml XSS hardening (new card color props into style=)', () => {
|
||||||
|
test('a cardBg breakout string cannot escape style=""', () => {
|
||||||
|
const malicious = '#fff" onmouseover="alert(1)';
|
||||||
|
const { html } = toHtml({ plans, cardBg: malicious }, '');
|
||||||
|
expect(html).not.toMatch(/"\s+onmouseover="/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a textColor breakout string cannot escape style=""', () => {
|
||||||
|
const malicious = '#000" onmouseover="alert(1)';
|
||||||
|
const { html } = toHtml({ plans, textColor: malicious }, '');
|
||||||
|
expect(html).not.toMatch(/"\s+onmouseover="/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a btnBg breakout string cannot escape style=""', () => {
|
||||||
|
const malicious = '#000" onmouseover="alert(1)';
|
||||||
|
const { html } = toHtml({ plans, btnBg: malicious }, '');
|
||||||
|
expect(html).not.toMatch(/"\s+onmouseover="/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a btnColor breakout string cannot escape style=""', () => {
|
||||||
|
const malicious = '#000" onmouseover="alert(1)';
|
||||||
|
const { html } = toHtml({ plans, btnColor: malicious }, '');
|
||||||
|
expect(html).not.toMatch(/"\s+onmouseover="/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('PricingTable.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('the new regular-card color props are declared blank by default', () => {
|
||||||
|
const props = (PricingTable as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('cardBg', '');
|
||||||
|
expect(props).toHaveProperty('textColor', '');
|
||||||
|
expect(props).toHaveProperty('subColor', '');
|
||||||
|
expect(props).toHaveProperty('featColor', '');
|
||||||
|
expect(props).toHaveProperty('checkColor', '');
|
||||||
|
expect(props).toHaveProperty('btnBg', '');
|
||||||
|
expect(props).toHaveProperty('btnColor', '');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (PricingTable as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -19,6 +19,23 @@ interface PricingTableProps {
|
|||||||
featuredBg?: string;
|
featuredBg?: string;
|
||||||
bulletType?: string;
|
bulletType?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
/* ---- Regular (non-featured) card colors ----
|
||||||
|
All optional; each falls back to the exact literal the card was
|
||||||
|
previously hard-coded to (or, for the button, to featuredBg -- the
|
||||||
|
button's original derivation) when left unset, so existing saved
|
||||||
|
projects render pixel-identical until a color is explicitly picked. */
|
||||||
|
cardBg?: string;
|
||||||
|
textColor?: string;
|
||||||
|
subColor?: string;
|
||||||
|
featColor?: string;
|
||||||
|
checkColor?: string;
|
||||||
|
btnBg?: string;
|
||||||
|
btnColor?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bulletChars: Record<string, string> = {
|
const bulletChars: Record<string, string> = {
|
||||||
@@ -61,6 +78,13 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
featuredBg = '#3b82f6',
|
featuredBg = '#3b82f6',
|
||||||
bulletType = 'check',
|
bulletType = 'check',
|
||||||
anchorId,
|
anchorId,
|
||||||
|
cardBg,
|
||||||
|
textColor,
|
||||||
|
subColor,
|
||||||
|
featColor,
|
||||||
|
checkColor,
|
||||||
|
btnBg,
|
||||||
|
btnColor,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
connectors: { connect, drag },
|
connectors: { connect, drag },
|
||||||
@@ -69,6 +93,14 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
selected: node.events.selected,
|
selected: node.events.selected,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const regCardBg = cardBg || '#ffffff';
|
||||||
|
const regTextColor = textColor || '#18181b';
|
||||||
|
const regSubColor = subColor || '#64748b';
|
||||||
|
const regFeatColor = featColor || '#4b5563';
|
||||||
|
const regCheckColor = checkColor || '#10b981';
|
||||||
|
const regBtnBg = btnBg || featuredBg;
|
||||||
|
const regBtnColor = btnColor || '#ffffff';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
||||||
@@ -95,7 +127,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
style={{
|
style={{
|
||||||
flex: '1 1 280px',
|
flex: '1 1 280px',
|
||||||
maxWidth: '360px',
|
maxWidth: '360px',
|
||||||
backgroundColor: plan.isFeatured ? featuredBg : '#ffffff',
|
backgroundColor: plan.isFeatured ? featuredBg : regCardBg,
|
||||||
border: plan.isFeatured ? 'none' : '1px solid #e2e8f0',
|
border: plan.isFeatured ? 'none' : '1px solid #e2e8f0',
|
||||||
borderRadius: '16px',
|
borderRadius: '16px',
|
||||||
padding: '40px 32px',
|
padding: '40px 32px',
|
||||||
@@ -127,7 +159,7 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
<h3 style={{
|
<h3 style={{
|
||||||
fontSize: '20px',
|
fontSize: '20px',
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
||||||
marginBottom: '8px',
|
marginBottom: '8px',
|
||||||
marginTop: plan.isFeatured ? '8px' : '0',
|
marginTop: plan.isFeatured ? '8px' : '0',
|
||||||
}}>
|
}}>
|
||||||
@@ -137,14 +169,14 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
<span style={{
|
<span style={{
|
||||||
fontSize: '48px',
|
fontSize: '48px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
color: plan.isFeatured ? '#ffffff' : '#18181b',
|
color: plan.isFeatured ? '#ffffff' : regTextColor,
|
||||||
lineHeight: '1',
|
lineHeight: '1',
|
||||||
}}>
|
}}>
|
||||||
{plan.price}
|
{plan.price}
|
||||||
</span>
|
</span>
|
||||||
<span style={{
|
<span style={{
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b',
|
color: plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor,
|
||||||
}}>
|
}}>
|
||||||
{plan.period}
|
{plan.period}
|
||||||
</span>
|
</span>
|
||||||
@@ -161,12 +193,12 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
{(Array.isArray(plan.features) ? plan.features : []).map((feature, fi) => (
|
{(Array.isArray(plan.features) ? plan.features : []).map((feature, fi) => (
|
||||||
<li key={fi} style={{
|
<li key={fi} style={{
|
||||||
fontSize: '14px',
|
fontSize: '14px',
|
||||||
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563',
|
color: plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
gap: '8px',
|
gap: '8px',
|
||||||
}}>
|
}}>
|
||||||
<span style={{ color: plan.isFeatured ? '#bbf7d0' : '#10b981', fontWeight: '700' }}>{bulletChars[bulletType] || '✓'}</span>
|
<span style={{ color: plan.isFeatured ? '#bbf7d0' : regCheckColor, fontWeight: '700' }}>{bulletChars[bulletType] || '✓'}</span>
|
||||||
{feature}
|
{feature}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@@ -178,8 +210,8 @@ export const PricingTable: UserComponent<PricingTableProps> = ({
|
|||||||
marginTop: 'auto',
|
marginTop: 'auto',
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
padding: '14px 32px',
|
padding: '14px 32px',
|
||||||
backgroundColor: plan.isFeatured ? '#ffffff' : featuredBg,
|
backgroundColor: plan.isFeatured ? '#ffffff' : regBtnBg,
|
||||||
color: plan.isFeatured ? featuredBg : '#ffffff',
|
color: plan.isFeatured ? featuredBg : regBtnColor,
|
||||||
textDecoration: 'none',
|
textDecoration: 'none',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px',
|
||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
@@ -207,6 +239,18 @@ PricingTable.craft = {
|
|||||||
featuredBg: '#3b82f6',
|
featuredBg: '#3b82f6',
|
||||||
bulletType: 'check',
|
bulletType: 'check',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
cardBg: '',
|
||||||
|
textColor: '',
|
||||||
|
subColor: '',
|
||||||
|
featColor: '',
|
||||||
|
checkColor: '',
|
||||||
|
btnBg: '',
|
||||||
|
btnColor: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
@@ -228,16 +272,28 @@ PricingTable.craft = {
|
|||||||
// Sanitized -- featuredBg is a raw string-interpolation sink below (drives
|
// Sanitized -- featuredBg is a raw string-interpolation sink below (drives
|
||||||
// cardBg/btnBg/btnColor, all raw-interpolated into style="...").
|
// cardBg/btnBg/btnColor, all raw-interpolated into style="...").
|
||||||
const featuredBg = cssValue(props.featuredBg) || '#3b82f6';
|
const featuredBg = cssValue(props.featuredBg) || '#3b82f6';
|
||||||
|
// Sanitized -- regular (non-featured) card color overrides, all raw
|
||||||
|
// string-interpolation sinks into style="..." below. Each falls back to
|
||||||
|
// the exact literal the card was previously hard-coded to (or, for the
|
||||||
|
// button, to featuredBg) when unset, so unmodified pricing tables render
|
||||||
|
// identically to before these props existed.
|
||||||
|
const regCardBg = cssValue(props.cardBg) || '#ffffff';
|
||||||
|
const regTextColor = cssValue(props.textColor) || '#18181b';
|
||||||
|
const regSubColor = cssValue(props.subColor) || '#64748b';
|
||||||
|
const regFeatColor = cssValue(props.featColor) || '#4b5563';
|
||||||
|
const regCheckColor = cssValue(props.checkColor) || '#10b981';
|
||||||
|
const regBtnBg = cssValue(props.btnBg) || featuredBg;
|
||||||
|
const regBtnColor = cssValue(props.btnColor) || '#ffffff';
|
||||||
|
|
||||||
const cards = plans.map((plan) => {
|
const cards = plans.map((plan) => {
|
||||||
const cardBg = plan.isFeatured ? featuredBg : '#ffffff';
|
const cardBg = plan.isFeatured ? featuredBg : regCardBg;
|
||||||
const cardBorder = plan.isFeatured ? 'border:none;' : 'border:1px solid #e2e8f0;';
|
const cardBorder = plan.isFeatured ? 'border:none;' : 'border:1px solid #e2e8f0;';
|
||||||
const textColor = plan.isFeatured ? '#ffffff' : '#18181b';
|
const textColor = plan.isFeatured ? '#ffffff' : regTextColor;
|
||||||
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : '#64748b';
|
const subColor = plan.isFeatured ? 'rgba(255,255,255,0.8)' : regSubColor;
|
||||||
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : '#4b5563';
|
const featColor = plan.isFeatured ? 'rgba(255,255,255,0.9)' : regFeatColor;
|
||||||
const checkColor = plan.isFeatured ? '#bbf7d0' : '#10b981';
|
const checkColor = plan.isFeatured ? '#bbf7d0' : regCheckColor;
|
||||||
const btnBg = plan.isFeatured ? '#ffffff' : featuredBg;
|
const btnBg = plan.isFeatured ? '#ffffff' : regBtnBg;
|
||||||
const btnColor = plan.isFeatured ? featuredBg : '#ffffff';
|
const btnColor = plan.isFeatured ? featuredBg : regBtnColor;
|
||||||
const scale = plan.isFeatured ? 'transform:scale(1.05);' : '';
|
const scale = plan.isFeatured ? 'transform:scale(1.05);' : '';
|
||||||
const shadow = plan.isFeatured ? 'box-shadow:0 20px 60px rgba(59,130,246,0.3);' : 'box-shadow:0 1px 3px rgba(0,0,0,0.06);';
|
const shadow = plan.isFeatured ? 'box-shadow:0 20px 60px rgba(59,130,246,0.3);' : 'box-shadow:0 1px 3px rgba(0,0,0,0.06);';
|
||||||
|
|
||||||
|
|||||||
@@ -80,3 +80,14 @@ describe('Tabs.toHtml deterministic + unique ids (thread node id, resolves id-co
|
|||||||
expect(html1).toBe(html2);
|
expect(html1).toBe(html2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Tabs.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (Tabs as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ interface TabsProps {
|
|||||||
inactiveTabColor?: string;
|
inactiveTabColor?: string;
|
||||||
contentBg?: string;
|
contentBg?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTabs: TabItem[] = [
|
const defaultTabs: TabItem[] = [
|
||||||
@@ -114,6 +119,11 @@ Tabs.craft = {
|
|||||||
inactiveTabColor: '#64748b',
|
inactiveTabColor: '#64748b',
|
||||||
contentBg: '#ffffff',
|
contentBg: '#ffffff',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -71,3 +71,14 @@ describe('Testimonials.toHtml rating aria-label sink (attacker-controlled `ratin
|
|||||||
expect(html).toContain('aria-label="Rating: 4 out of 5"');
|
expect(html).toContain('aria-label="Rating: 4 out of 5"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Testimonials.craft.props includes the box-model/animation/visibility rollout props', () => {
|
||||||
|
test('animation, animationDelay, and all 3 hideOn* flags are declared (blank/false defaults)', () => {
|
||||||
|
const props = (Testimonials as any).craft.props;
|
||||||
|
expect(props).toHaveProperty('animation', '');
|
||||||
|
expect(props).toHaveProperty('animationDelay', '');
|
||||||
|
expect(props).toHaveProperty('hideOnDesktop', false);
|
||||||
|
expect(props).toHaveProperty('hideOnTablet', false);
|
||||||
|
expect(props).toHaveProperty('hideOnMobile', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ interface TestimonialsProps {
|
|||||||
cardBg?: string;
|
cardBg?: string;
|
||||||
starColor?: string;
|
starColor?: string;
|
||||||
anchorId?: string;
|
anchorId?: string;
|
||||||
|
animation?: string;
|
||||||
|
animationDelay?: string;
|
||||||
|
hideOnDesktop?: boolean;
|
||||||
|
hideOnTablet?: boolean;
|
||||||
|
hideOnMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultTestimonials: Testimonial[] = [
|
const defaultTestimonials: Testimonial[] = [
|
||||||
@@ -131,6 +136,11 @@ Testimonials.craft = {
|
|||||||
cardBg: '#f8fafc',
|
cardBg: '#f8fafc',
|
||||||
starColor: '#f59e0b',
|
starColor: '#f59e0b',
|
||||||
anchorId: '',
|
anchorId: '',
|
||||||
|
animation: '',
|
||||||
|
animationDelay: '',
|
||||||
|
hideOnDesktop: false,
|
||||||
|
hideOnTablet: false,
|
||||||
|
hideOnMobile: false,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
canDrag: () => true,
|
canDrag: () => true,
|
||||||
|
|||||||
@@ -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' },
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
import { useEditor } from '@craftjs/core';
|
import { useEditor } from '@craftjs/core';
|
||||||
|
import { SHADOW_PRESETS } from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
CollapsibleSection,
|
CollapsibleSection,
|
||||||
ColorPickerField,
|
ColorPickerField,
|
||||||
|
SectionLabel,
|
||||||
|
PresetButtonGrid,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
inputStyle,
|
inputStyle,
|
||||||
smallInputStyle,
|
smallInputStyle,
|
||||||
btnActiveStyle,
|
btnActiveStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
|
useNodeProp,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
|
/** Parses a border shorthand string ("2px solid #hex") produced by
|
||||||
|
* buildBorderShorthand() back into its parts for round-tripping through
|
||||||
|
* BorderControl. See SectionTypePanel.tsx for the identical helper. */
|
||||||
|
function parseBorderShorthand(v: string | undefined): BorderValue {
|
||||||
|
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
||||||
|
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '#000000' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
|
||||||
const bulletOptions = [
|
const bulletOptions = [
|
||||||
{ label: '✓', value: 'check' },
|
{ label: '✓', value: 'check' },
|
||||||
{ label: '●', value: 'dot' },
|
{ label: '●', value: 'dot' },
|
||||||
@@ -26,10 +48,12 @@ const bulletChar: Record<string, string> = {
|
|||||||
|
|
||||||
export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
const [expandedPlan, setExpandedPlan] = useState<number>(0);
|
const [expandedPlan, setExpandedPlan] = useState<number>(0);
|
||||||
|
|
||||||
const plans: any[] = Array.isArray(nodeProps.plans) ? nodeProps.plans : [];
|
const plans: any[] = Array.isArray(nodeProps.plans) ? nodeProps.plans : [];
|
||||||
const currentBullet = nodeProps.bulletType || 'check';
|
const currentBullet = nodeProps.bulletType || 'check';
|
||||||
|
const style = nodeProps.style || {};
|
||||||
|
|
||||||
const updatePlan = useCallback((planIndex: number, field: string, value: any) => {
|
const updatePlan = useCallback((planIndex: number, field: string, value: any) => {
|
||||||
actions.setProp(selectedId, (props: any) => {
|
actions.setProp(selectedId, (props: any) => {
|
||||||
@@ -204,6 +228,79 @@ export const PricingStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeP
|
|||||||
{/* Colors */}
|
{/* Colors */}
|
||||||
<CollapsibleSection title="Colors" defaultOpen={false}>
|
<CollapsibleSection title="Colors" defaultOpen={false}>
|
||||||
<ColorPickerField label="Featured Plan Color" value={nodeProps.featuredBg || '#3b82f6'} onChange={(v) => actions.setProp(selectedId, (p: any) => { p.featuredBg = v; })} />
|
<ColorPickerField label="Featured Plan Color" value={nodeProps.featuredBg || '#3b82f6'} onChange={(v) => actions.setProp(selectedId, (p: any) => { p.featuredBg = v; })} />
|
||||||
|
{/* Regular (non-featured) card colors -- built into PricingTable's
|
||||||
|
render/toHtml but previously hard-coded literals with no control
|
||||||
|
surfacing them. Each falls back to the prior literal when blank. */}
|
||||||
|
<ColorPickerField label="Card Background" value={nodeProps.cardBg || '#ffffff'} onChange={(v) => setProp('cardBg', v)} />
|
||||||
|
<ColorPickerField label="Heading / Price Color" value={nodeProps.textColor || '#18181b'} onChange={(v) => setProp('textColor', v)} />
|
||||||
|
<ColorPickerField label="Period Text Color" value={nodeProps.subColor || '#64748b'} onChange={(v) => setProp('subColor', v)} />
|
||||||
|
<ColorPickerField label="Feature Text Color" value={nodeProps.featColor || '#4b5563'} onChange={(v) => setProp('featColor', v)} />
|
||||||
|
<ColorPickerField label="Checkmark Color" value={nodeProps.checkColor || '#10b981'} onChange={(v) => setProp('checkColor', v)} />
|
||||||
|
<ColorPickerField label="Button Background" value={nodeProps.btnBg || nodeProps.featuredBg || '#3b82f6'} onChange={(v) => setProp('btnBg', v)} />
|
||||||
|
<ColorPickerField label="Button Text Color" value={nodeProps.btnColor || '#ffffff'} onChange={(v) => setProp('btnColor', v)} />
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Box model: margin, padding, border, shadow, opacity */}
|
||||||
|
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{
|
||||||
|
top: style.marginTop as string, right: style.marginRight as string,
|
||||||
|
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding"
|
||||||
|
value={{
|
||||||
|
top: style.paddingTop as string, right: style.paddingRight as string,
|
||||||
|
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderShorthand(style.border as string)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Shadow</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
||||||
|
</div>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Opacity</SectionLabel>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
||||||
|
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Entrance animation */}
|
||||||
|
<CollapsibleSection title="Animation" defaultOpen={false}>
|
||||||
|
<AnimationControl
|
||||||
|
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
||||||
|
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Responsive visibility */}
|
||||||
|
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
||||||
|
<VisibilityControl
|
||||||
|
value={{
|
||||||
|
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
||||||
|
hideOnTablet: !!nodeProps.hideOnTablet,
|
||||||
|
hideOnMobile: !!nodeProps.hideOnMobile,
|
||||||
|
}}
|
||||||
|
onChange={(v) => {
|
||||||
|
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
||||||
|
setProp('hideOnTablet', !!v.hideOnTablet);
|
||||||
|
setProp('hideOnMobile', !!v.hideOnMobile);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
BG_COLORS,
|
BG_COLORS,
|
||||||
SPACING_PRESETS,
|
SPACING_PRESETS,
|
||||||
RADIUS_PRESETS,
|
RADIUS_PRESETS,
|
||||||
|
SHADOW_PRESETS,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
@@ -15,10 +16,31 @@ import {
|
|||||||
inputStyle,
|
inputStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { FeaturesEditor } from './FeaturesEditor';
|
import { FeaturesEditor } from './FeaturesEditor';
|
||||||
import { ArrayItemFieldsEditor } from './ArrayItemFields';
|
import { ArrayItemFieldsEditor } from './ArrayItemFields';
|
||||||
|
|
||||||
|
/** Parses a border shorthand string ("2px solid #hex") produced by
|
||||||
|
* buildBorderShorthand() back into its parts for round-tripping through
|
||||||
|
* BorderControl. Anything that doesn't match (undefined/'none'/legacy
|
||||||
|
* hand-authored values) falls back to an empty/none border rather than
|
||||||
|
* throwing, since this is display-only -- the next edit always re-emits a
|
||||||
|
* clean shorthand via buildBorderShorthand(). */
|
||||||
|
function parseBorderShorthand(v: string | undefined): BorderValue {
|
||||||
|
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
||||||
|
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '#000000' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
|
||||||
/* ---------- SECTION-TYPE (Accordion, Tabs, Pricing, Testimonials, etc.) ---------- */
|
/* ---------- SECTION-TYPE (Accordion, Tabs, Pricing, Testimonials, etc.) ---------- */
|
||||||
export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }> = ({ selectedId, nodeProps, typeName }) => {
|
export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }> = ({ selectedId, nodeProps, typeName }) => {
|
||||||
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
const { setProp, setPropStyle } = useNodeProp(selectedId);
|
||||||
@@ -26,7 +48,12 @@ export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }>
|
|||||||
const style = nodeProps.style || {};
|
const style = nodeProps.style || {};
|
||||||
|
|
||||||
// Find all string/number/boolean props
|
// Find all string/number/boolean props
|
||||||
const SKIP_PROPS = new Set(['style', 'children', 'cssId', 'cssClass']);
|
const SKIP_PROPS = new Set([
|
||||||
|
'style', 'children', 'cssId', 'cssClass',
|
||||||
|
// Rendered via dedicated controls below (Animation/Visibility), not the
|
||||||
|
// generic Content field dump -- otherwise they'd show up twice.
|
||||||
|
'animation', 'animationDelay', 'hideOnDesktop', 'hideOnTablet', 'hideOnMobile',
|
||||||
|
]);
|
||||||
const scalarProps = Object.entries(nodeProps).filter(
|
const scalarProps = Object.entries(nodeProps).filter(
|
||||||
([key, val]) => !SKIP_PROPS.has(key) && (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean')
|
([key, val]) => !SKIP_PROPS.has(key) && (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean')
|
||||||
);
|
);
|
||||||
@@ -126,6 +153,69 @@ export const SectionTypePanel: React.FC<StylePanelProps & { typeName: string }>
|
|||||||
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
<PresetButtonGrid presets={RADIUS_PRESETS} activeValue={style.borderRadius as string} onSelect={(v) => setPropStyle('borderRadius', v)} />
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Box model: margin, padding, border, shadow, opacity */}
|
||||||
|
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{
|
||||||
|
top: style.marginTop as string, right: style.marginRight as string,
|
||||||
|
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding"
|
||||||
|
value={{
|
||||||
|
top: style.paddingTop as string, right: style.paddingRight as string,
|
||||||
|
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderShorthand(style.border as string)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Shadow</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
||||||
|
</div>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Opacity</SectionLabel>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
||||||
|
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Entrance animation */}
|
||||||
|
<CollapsibleSection title="Animation" defaultOpen={false}>
|
||||||
|
<AnimationControl
|
||||||
|
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
||||||
|
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Responsive visibility */}
|
||||||
|
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
||||||
|
<VisibilityControl
|
||||||
|
value={{
|
||||||
|
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
||||||
|
hideOnTablet: !!nodeProps.hideOnTablet,
|
||||||
|
hideOnMobile: !!nodeProps.hideOnMobile,
|
||||||
|
}}
|
||||||
|
onChange={(v) => {
|
||||||
|
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
||||||
|
setProp('hideOnTablet', !!v.hideOnTablet);
|
||||||
|
setProp('hideOnMobile', !!v.hideOnMobile);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useEditor } from '@craftjs/core';
|
|||||||
import {
|
import {
|
||||||
BG_COLORS,
|
BG_COLORS,
|
||||||
SPACING_PRESETS,
|
SPACING_PRESETS,
|
||||||
|
SHADOW_PRESETS,
|
||||||
} from '../../../constants/presets';
|
} from '../../../constants/presets';
|
||||||
import {
|
import {
|
||||||
StylePanelProps,
|
StylePanelProps,
|
||||||
@@ -17,8 +18,33 @@ import {
|
|||||||
btnActiveStyle,
|
btnActiveStyle,
|
||||||
sectionGap,
|
sectionGap,
|
||||||
useNodeProp,
|
useNodeProp,
|
||||||
|
SpacingControl,
|
||||||
|
BorderControl,
|
||||||
|
BorderValue,
|
||||||
|
buildBorderShorthand,
|
||||||
|
AnimationControl,
|
||||||
|
VisibilityControl,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
|
||||||
|
/** Parses a border shorthand string ("2px solid #hex") produced by
|
||||||
|
* buildBorderShorthand() back into its parts for round-tripping through
|
||||||
|
* BorderControl. See SectionTypePanel.tsx for the identical helper. */
|
||||||
|
function parseBorderShorthand(v: string | undefined): BorderValue {
|
||||||
|
if (!v || v === 'none') return { width: '', style: 'none', color: '#000000' };
|
||||||
|
const m = String(v).match(/^([\d.]+[a-z%]*)\s+(\w+)\s+(.+)$/);
|
||||||
|
if (!m) return { width: '', style: 'none', color: '#000000' };
|
||||||
|
return { width: m[1], style: m[2], color: m[3] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const capSide = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
|
||||||
|
const ICON_SHAPES = [
|
||||||
|
{ label: 'None', value: 'none' },
|
||||||
|
{ label: 'Circle', value: 'circle' },
|
||||||
|
{ label: 'Square', value: 'square' },
|
||||||
|
{ label: 'Rounded', value: 'rounded' },
|
||||||
|
];
|
||||||
|
|
||||||
/* ---------- SOCIAL / ICON / STAR RATING ---------- */
|
/* ---------- SOCIAL / ICON / STAR RATING ---------- */
|
||||||
export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||||
const { actions } = useEditor();
|
const { actions } = useEditor();
|
||||||
@@ -111,6 +137,72 @@ export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePr
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Icon shape (SocialLinks) -- exists on the component (iconShape prop
|
||||||
|
drives the circle/square/rounded background box) but previously had
|
||||||
|
no control. */}
|
||||||
|
{nodeProps.iconShape !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Icon Shape</label>
|
||||||
|
<div style={{ display: 'flex', gap: 4 }}>
|
||||||
|
{ICON_SHAPES.map((s) => (
|
||||||
|
<button key={s.value} onClick={() => setProp('iconShape', s.value)} style={{ ...btnActiveStyle(nodeProps.iconShape === s.value), flex: 1 }}>
|
||||||
|
{s.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{/* Gap between links (SocialLinks) -- exists on the component but
|
||||||
|
previously had no control. */}
|
||||||
|
{nodeProps.gap !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Gap</label>
|
||||||
|
<input type="text" value={nodeProps.gap || '10px'} onChange={(e) => setProp('gap', e.target.value)} placeholder="10px" style={inputStyle} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Background shape / size / link (Icon component) -- bgColor, bgShape,
|
||||||
|
bgSize, link all already exist on Icon.craft.props but had no
|
||||||
|
control; the generic `color`/`iconColor` checks above never matched
|
||||||
|
Icon's actual prop names. */}
|
||||||
|
{nodeProps.bgShape !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Background Shape</label>
|
||||||
|
<div style={{ display: 'flex', gap: 4 }}>
|
||||||
|
{ICON_SHAPES.map((s) => (
|
||||||
|
<button key={s.value} onClick={() => setProp('bgShape', s.value)} style={{ ...btnActiveStyle(nodeProps.bgShape === s.value), flex: 1 }}>
|
||||||
|
{s.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{nodeProps.bgColor !== undefined && (
|
||||||
|
<ColorPickerField label="Background Color" value={nodeProps.bgColor === 'transparent' ? '' : nodeProps.bgColor} onChange={(v) => setProp('bgColor', v)} />
|
||||||
|
)}
|
||||||
|
{nodeProps.bgSize !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Background Size</label>
|
||||||
|
<input type="text" value={nodeProps.bgSize || '56px'} onChange={(e) => setProp('bgSize', e.target.value)} placeholder="56px" style={inputStyle} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{nodeProps.link !== undefined && (
|
||||||
|
<div style={sectionGap}>
|
||||||
|
<label style={labelStyle}>Link URL</label>
|
||||||
|
<input type="text" value={nodeProps.link || ''} onChange={(e) => setProp('link', e.target.value)} placeholder="https://..." style={inputStyle} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Star colors (StarRating) -- exist on the component as filledColor /
|
||||||
|
emptyColor but had no control (the generic `starColor` check above
|
||||||
|
never matched StarRating's actual prop names). */}
|
||||||
|
{nodeProps.filledColor !== undefined && (
|
||||||
|
<ColorPickerField label="Filled Star Color" value={nodeProps.filledColor || '#f59e0b'} onChange={(v) => setProp('filledColor', v)} />
|
||||||
|
)}
|
||||||
|
{nodeProps.emptyColor !== undefined && (
|
||||||
|
<ColorPickerField label="Empty Star Color" value={nodeProps.emptyColor || '#d1d5db'} onChange={(v) => setProp('emptyColor', v)} />
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Colors */}
|
{/* Colors */}
|
||||||
{nodeProps.iconColor !== undefined && (
|
{nodeProps.iconColor !== undefined && (
|
||||||
<ColorPickerField label="Icon Color" value={nodeProps.iconColor || '#3b82f6'} onChange={(v) => setProp('iconColor', v)} />
|
<ColorPickerField label="Icon Color" value={nodeProps.iconColor || '#3b82f6'} onChange={(v) => setProp('iconColor', v)} />
|
||||||
@@ -164,6 +256,69 @@ export const SocialStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodePr
|
|||||||
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={style.padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
<PresetButtonGrid presets={SPACING_PRESETS} activeValue={style.padding as string} onSelect={(v) => setPropStyle('padding', v)} />
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Box model: margin, padding (per-side), border, shadow, opacity */}
|
||||||
|
<CollapsibleSection title="Spacing & Border" defaultOpen={false}>
|
||||||
|
<SpacingControl
|
||||||
|
label="Margin"
|
||||||
|
value={{
|
||||||
|
top: style.marginTop as string, right: style.marginRight as string,
|
||||||
|
bottom: style.marginBottom as string, left: style.marginLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`margin${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<SpacingControl
|
||||||
|
label="Padding"
|
||||||
|
value={{
|
||||||
|
top: style.paddingTop as string, right: style.paddingRight as string,
|
||||||
|
bottom: style.paddingBottom as string, left: style.paddingLeft as string,
|
||||||
|
}}
|
||||||
|
onChange={(side, v) => setPropStyle(`padding${capSide(side)}`, v)}
|
||||||
|
/>
|
||||||
|
<BorderControl
|
||||||
|
value={parseBorderShorthand(style.border as string)}
|
||||||
|
onChange={(v) => setPropStyle('border', buildBorderShorthand(v))}
|
||||||
|
/>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Shadow</SectionLabel>
|
||||||
|
<PresetButtonGrid presets={SHADOW_PRESETS} activeValue={style.boxShadow as string} onSelect={(v) => setPropStyle('boxShadow', v)} />
|
||||||
|
</div>
|
||||||
|
<div className="guided-section">
|
||||||
|
<SectionLabel>Opacity</SectionLabel>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
value={style.opacity !== undefined ? Math.round(Number(style.opacity) * 100) : 100}
|
||||||
|
onChange={(e) => setPropStyle('opacity', String(Number(e.target.value) / 100))}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Entrance animation */}
|
||||||
|
<CollapsibleSection title="Animation" defaultOpen={false}>
|
||||||
|
<AnimationControl
|
||||||
|
value={{ animation: nodeProps.animation || 'none', animationDelay: nodeProps.animationDelay || '0' }}
|
||||||
|
onChange={(v) => { setProp('animation', v.animation); setProp('animationDelay', v.animationDelay); }}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
|
|
||||||
|
{/* Responsive visibility */}
|
||||||
|
<CollapsibleSection title="Visibility" defaultOpen={false}>
|
||||||
|
<VisibilityControl
|
||||||
|
value={{
|
||||||
|
hideOnDesktop: !!nodeProps.hideOnDesktop,
|
||||||
|
hideOnTablet: !!nodeProps.hideOnTablet,
|
||||||
|
hideOnMobile: !!nodeProps.hideOnMobile,
|
||||||
|
}}
|
||||||
|
onChange={(v) => {
|
||||||
|
setProp('hideOnDesktop', !!v.hideOnDesktop);
|
||||||
|
setProp('hideOnTablet', !!v.hideOnTablet);
|
||||||
|
setProp('hideOnMobile', !!v.hideOnMobile);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CollapsibleSection>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,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