| 1 |
/** |
| 2 |
* Campaign element registry — reads from PHP-localized data. |
| 3 |
* |
| 4 |
* PHP (CampaignElements.php) defines element schemas and localizes them to |
| 5 |
* window.betterPaymentCampaignData.elements. This module provides a typed |
| 6 |
* interface over that data so the rest of the builder doesn't access the |
| 7 |
* global directly. |
| 8 |
* |
| 9 |
* Falls back to a minimal built-in list when the global is unavailable |
| 10 |
* (e.g., during unit tests or when wp_localize_script hasn't run). |
| 11 |
*/ |
| 12 |
|
| 13 |
const FALLBACK = [ |
| 14 |
{ type: 'campaign_title', label: 'Campaign Title', icon: 'heading', defaultSettings: { font_size: '2rem', color: '#1a1a2e' }, settingsSchema: [] }, |
| 15 |
{ type: 'campaign_description', label: 'Description', icon: 'editor-paragraph', defaultSettings: {}, settingsSchema: [] }, |
| 16 |
{ type: 'photo', label: 'Photo', icon: 'format-image', defaultSettings: { src: '', src_id: 0, src_sizes: {}, alt: '', size: 'full', width: 100, align: 'center' }, settingsSchema: [] }, |
| 17 |
{ type: 'progress_bar', label: 'Progress Bar', icon: 'chart-bar', defaultSettings: { show_percent: true, show_amounts: true }, settingsSchema: [] }, |
| 18 |
{ type: 'campaign_summary', label: 'Campaign Summary', icon: 'info', defaultSettings: { show_raised: true, show_donors: true, show_days: true }, settingsSchema: [] }, |
| 19 |
{ type: 'donation_form', label: 'Donate Button', icon: 'heart', defaultSettings: { button_text: 'Donate Now' }, settingsSchema: [] }, |
| 20 |
{ type: 'organizer', label: 'Organizer', icon: 'admin-users', defaultSettings: { show_avatar: true, show_name: true, label: 'Campaign by' }, settingsSchema: [] }, |
| 21 |
{ type: 'donate_amount', label: 'Donate Amount', icon: 'money-alt', defaultSettings: { preset_amounts: '10,25,50,100', allow_custom: true }, settingsSchema: [] }, |
| 22 |
{ type: 'social_sharing', label: 'Social Sharing', icon: 'share', defaultSettings: { show_facebook: true, show_twitter: true, show_whatsapp: true }, settingsSchema: [] }, |
| 23 |
{ type: 'social_links', label: 'Social Links', icon: 'admin-links', defaultSettings: { facebook: '', twitter: '', instagram: '', youtube: '', website: '' }, settingsSchema: [] }, |
| 24 |
]; |
| 25 |
|
| 26 |
function getRegistry() { |
| 27 |
return window?.betterPaymentCampaignData?.elements || FALLBACK; |
| 28 |
} |
| 29 |
|
| 30 |
export function getAllElements() { |
| 31 |
return getRegistry(); |
| 32 |
} |
| 33 |
|
| 34 |
export function getElement( type ) { |
| 35 |
return getRegistry().find( ( el ) => el.type === type ) || null; |
| 36 |
} |
| 37 |
|
| 38 |
export function getDefaultSettings( type ) { |
| 39 |
return getElement( type )?.defaultSettings || {}; |
| 40 |
} |
| 41 |
|
| 42 |
export default getAllElements; |
| 43 |
|