PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / multi-step-form / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/multi-step-form/index.js

428 lines 35.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var el = wp.element.createElement;
3 var Fragment = wp.element.Fragment;
4 var useState = wp.element.useState;
5 var __ = wp.i18n.__;
6 var registerBlockType = wp.blocks.registerBlockType;
7 var InspectorControls = wp.blockEditor.InspectorControls;
8 var RichText = wp.blockEditor.RichText;
9 var useBlockProps = wp.blockEditor.useBlockProps;
10 var PanelBody = wp.components.PanelBody;
11 var Button = wp.components.Button;
12 var ToggleControl = wp.components.ToggleControl;
13 var RangeControl = wp.components.RangeControl;
14 var SelectControl = wp.components.SelectControl;
15 var TextControl = wp.components.TextControl;
16 var TextareaControl = wp.components.TextareaControl;
17 var ColorPicker = wp.components.ColorPicker;
18 var Popover = wp.components.Popover;
19
20 var _tc, _tv;
21 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
22 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
23 var IP = function () { return window.bkbgIconPicker; };
24
25 var PROGRESS_STYLE_OPTIONS = [
26 { label: __('Step circles', 'blockenberg'), value: 'steps' },
27 { label: __('Progress bar', 'blockenberg'), value: 'bar' },
28 { label: __('Dots', 'blockenberg'), value: 'dots' },
29 ];
30 var FIELD_TYPE_OPTIONS = [
31 { label: __('Text', 'blockenberg'), value: 'text' },
32 { label: __('Email', 'blockenberg'), value: 'email' },
33 { label: __('Phone', 'blockenberg'), value: 'phone' },
34 { label: __('Textarea', 'blockenberg'), value: 'textarea' },
35 { label: __('Select', 'blockenberg'), value: 'select' },
36 { label: __('Radio', 'blockenberg'), value: 'radio' },
37 { label: __('Checkbox', 'blockenberg'), value: 'checkbox' },
38 ];
39
40 function makeId() { return 'msf' + Math.random().toString(36).substr(2, 5); }
41
42 function buildWrapStyle(a) {
43 return {
44 '--bkbg-msf-accent': a.accentColor,
45 '--bkbg-msf-active-step-bg': a.activeStepBg,
46 '--bkbg-msf-active-step-color': a.activeStepColor,
47 '--bkbg-msf-done-step-bg': a.completedStepBg,
48 '--bkbg-msf-done-step-color': a.completedStepColor,
49 '--bkbg-msf-idle-step-bg': a.pendingStepBg,
50 '--bkbg-msf-idle-step-color': a.pendingStepColor,
51 '--bkbg-msf-connector': a.connectorColor,
52 '--bkbg-msf-connector-done': a.connectorActiveColor,
53 '--bkbg-msf-step-title-color': a.stepTitleColor,
54 '--bkbg-msf-step-desc-color': a.stepDescColor,
55 '--bkbg-msf-label-color': a.labelColor,
56 '--bkbg-msf-input-bg': a.inputBg,
57 '--bkbg-msf-input-border': a.inputBorder,
58 '--bkbg-msf-input-text': a.inputText,
59 '--bkbg-msf-input-focus': a.inputFocusBorder,
60 '--bkbg-msf-btn-bg': a.btnBg,
61 '--bkbg-msf-btn-color': a.btnColor,
62 '--bkbg-msf-btn-sec-bg': a.btnSecBg,
63 '--bkbg-msf-btn-sec-color': a.btnSecColor,
64 '--bkbg-msf-card-bg': a.cardBg,
65 '--bkbg-msf-card-border': a.cardBorderColor,
66 '--bkbg-msf-step-circle-sz': a.stepCircleSize + 'px',
67 '--bkbg-msf-card-r': a.cardRadius + 'px',
68 '--bkbg-msf-card-pad': a.cardPadding + 'px',
69 '--bkbg-msf-input-r': a.inputRadius + 'px',
70 '--bkbg-msf-input-pad-v': a.inputPaddingV + 'px',
71 '--bkbg-msf-btn-r': a.btnRadius + 'px',
72 '--bkbg-msf-label-sz': a.labelSize + 'px',
73 '--bkbg-msf-input-sz': a.inputSize + 'px',
74 '--bkbg-msf-step-title-sz': a.stepTitleSize + 'px',
75 '--bkbg-msf-step-desc-sz': a.stepDescSize + 'px',
76 '--bkbg-msf-step-label-sz': a.stepLabelSize + 'px',
77 '--bkbg-msf-btn-sz': a.btnSize + 'px',
78 '--bkbg-msf-font-weight': a.fontWeight || 600,
79 '--bkbg-msf-line-height': a.lineHeight || 1.5,
80 paddingTop: a.paddingTop + 'px',
81 paddingBottom: a.paddingBottom + 'px',
82 backgroundColor: a.bgColor || undefined,
83 };
84 var _tvf = getTypoCssVars();
85 if (_tvf) {
86 Object.assign(s, _tvf(a.stepTitleTypo, '--bkbg-msf-tt-'));
87 Object.assign(s, _tvf(a.stepDescTypo, '--bkbg-msf-sd-'));
88 }
89 return s;
90 }
91
92 function renderColorControl(key, label, value, onChange, openKey, setOpenKey) {
93 var isOpen = openKey === key;
94 return el('div', { key: key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 0', gap: '8px' } },
95 el('span', { style: { fontSize: '12px', color: '#1e1e1e', flex: 1, lineHeight: 1.4 } }, label),
96 el('div', { style: { position: 'relative', flexShrink: 0 } },
97 el('button', { type: 'button', onClick: function () { setOpenKey(isOpen ? null : key); }, style: { width: '28px', height: '28px', borderRadius: '4px', border: isOpen ? '2px solid #007cba' : '2px solid #ddd', cursor: 'pointer', padding: 0, background: value || '#ccc' } }),
98 isOpen && el(Popover, { position: 'bottom left', onClose: function () { setOpenKey(null); } },
99 el('div', { style: { padding: '8px' } },
100 el(ColorPicker, { color: value, enableAlpha: true, onChange: onChange })
101 )
102 )
103 )
104 );
105 }
106
107 /* ── Field preview ─────────────────────────────────────────────── */
108 function FieldPreview(props) {
109 var field = props.field;
110 var a = props.a;
111 var inputStyle = {
112 width: '100%', boxSizing: 'border-box',
113 fontSize: a.inputSize + 'px', padding: a.inputPaddingV + 'px 14px',
114 borderRadius: a.inputRadius + 'px', border: '1.5px solid ' + a.inputBorder,
115 background: a.inputBg, color: a.inputText, fontFamily: 'inherit', outline: 'none',
116 };
117 return el('div', { className: 'bkbg-msf-field', style: { marginBottom: '16px' } },
118 el('label', { className: 'bkbg-msf-label', style: { display: 'block', marginBottom: '6px', fontSize: a.labelSize + 'px', fontWeight: 600, color: a.labelColor } },
119 field.label, field.required && el('span', { style: { color: a.accentColor, marginLeft: '3px' } }, '*')
120 ),
121 field.type === 'textarea' && el('textarea', { className: 'bkbg-msf-input', placeholder: field.placeholder, rows: 3, style: inputStyle, readOnly: true }),
122 (field.type === 'text' || field.type === 'email' || field.type === 'phone') && el('input', { type: field.type === 'phone' ? 'tel' : field.type, className: 'bkbg-msf-input', placeholder: field.placeholder, style: inputStyle, readOnly: true }),
123 field.type === 'select' && el('select', { className: 'bkbg-msf-input', style: inputStyle, disabled: true },
124 el('option', null, field.placeholder || __('Choose…', 'blockenberg')),
125 (field.options || []).map(function (opt, oi) { return el('option', { key: oi }, opt); })
126 ),
127 field.type === 'radio' && el('div', { className: 'bkbg-msf-radio-group', style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
128 (field.options || []).map(function (opt, oi) {
129 return el('label', { key: oi, style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: a.inputSize + 'px', cursor: 'pointer', color: a.inputText } },
130 el('input', { type: 'radio', disabled: true, readOnly: true }),
131 el('span', null, opt)
132 );
133 })
134 ),
135 field.type === 'checkbox' && el('label', { style: { display: 'flex', alignItems: 'flex-start', gap: '10px', fontSize: a.inputSize + 'px', cursor: 'pointer', color: a.inputText } },
136 el('input', { type: 'checkbox', disabled: true, style: { marginTop: '2px', flexShrink: 0 } }),
137 el('span', null, field.label)
138 )
139 );
140 }
141
142 /* ── Step indicator ────────────────────────────────────────────── */
143 function StepIndicator(props) {
144 var a = props.a;
145 var currentStep = props.currentStep;
146 var onClickStep = props.onClickStep;
147
148 if (a.progressStyle === 'bar') {
149 var pct = ((currentStep) / Math.max(1, a.steps.length - 1)) * 100;
150 return el('div', { className: 'bkbg-msf-progress-bar-wrap', style: { marginBottom: '32px' } },
151 el('div', { style: { height: '6px', borderRadius: '99px', background: a.pendingStepBg, overflow: 'hidden' } },
152 el('div', { className: 'bkbg-msf-progress-fill', style: { height: '100%', width: pct + '%', background: a.accentColor, transition: 'width 0.4s', borderRadius: '99px' } })
153 ),
154 a.showStepTitles && el('p', { style: { margin: '10px 0 0', fontSize: a.stepLabelSize + 'px', color: a.stepDescColor, textAlign: 'center' } },
155 __('Step', 'blockenberg') + ' ' + (currentStep + 1) + ' ' + __('of', 'blockenberg') + ' ' + a.steps.length
156 )
157 );
158 }
159
160 if (a.progressStyle === 'dots') {
161 return el('div', { className: 'bkbg-msf-dots', style: { display: 'flex', justifyContent: 'center', gap: '10px', marginBottom: '32px' } },
162 a.steps.map(function (s, si) {
163 var isDone = si < currentStep;
164 var isActive = si === currentStep;
165 return el('button', { key: s.id, type: 'button', title: s.title, onClick: function () { onClickStep(si); }, style: { width: isActive ? '24px' : '10px', height: '10px', borderRadius: '99px', border: 'none', cursor: 'pointer', padding: 0, transition: 'all 0.3s', background: isActive ? a.activeStepBg : (isDone ? a.completedStepBg : a.pendingStepBg) } });
166 })
167 );
168 }
169
170 /* steps (circles + connectors) */
171 return el('div', { className: 'bkbg-msf-steps-indicator', style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'center', marginBottom: '36px', position: 'relative' } },
172 a.steps.map(function (s, si) {
173 var isDone = si < currentStep;
174 var isActive = si === currentStep;
175 var circleBg = isActive ? a.activeStepBg : (isDone ? a.completedStepBg : a.pendingStepBg);
176 var circleColor = isActive ? a.activeStepColor : (isDone ? a.completedStepColor : a.pendingStepColor);
177 return el('div', { key: s.id, style: { display: 'flex', flexDirection: 'column', alignItems: 'center', flex: si < a.steps.length - 1 ? '1' : '0', minWidth: '60px' } },
178 el('div', { style: { display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'center', position: 'relative' } },
179 el('button', { type: 'button', onClick: function () { onClickStep(si); }, style: { width: a.stepCircleSize + 'px', height: a.stepCircleSize + 'px', borderRadius: '50%', border: 'none', cursor: 'pointer', background: circleBg, color: circleColor, fontSize: a.stepCircleSize * 0.38 + 'px', fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, position: 'relative', zIndex: 1, transition: 'all 0.25s' } },
180 a.showStepIcons && s.icon ? (function () {
181 var _st = s.iconType || 'custom-char';
182 if (_st !== 'custom-char' && IP()) {
183 var _n = IP().buildEditorIcon(_st, s.icon, s.iconDashicon, s.iconImageUrl, s.iconDashiconColor);
184 if (_n) return el('span', null, _n);
185 }
186 return el('span', null, s.icon);
187 })() : (a.showStepNumbers ? el('span', null, si + 1) : el('span', null, isDone ? '' : ''))
188 ),
189 si < a.steps.length - 1 && el('div', { style: { flex: 1, height: '3px', background: isDone ? a.connectorActiveColor : a.connectorColor, marginLeft: '2px', transition: 'background 0.3s' } })
190 ),
191 a.showStepTitles && el('span', { style: { marginTop: '8px', fontSize: a.stepLabelSize + 'px', fontWeight: isActive ? 700 : 500, color: isActive ? a.accentColor : a.stepDescColor, textAlign: 'center', maxWidth: '80px' } }, s.title)
192 );
193 })
194 );
195 }
196
197 registerBlockType('blockenberg/multi-step-form', {
198 title: __('Multi-Step Form', 'blockenberg'),
199 icon: 'feedback',
200 category: 'bkbg-marketing',
201
202 edit: function (props) {
203 var a = props.attributes;
204 var setAttributes = props.setAttributes;
205
206 var openColorKeyState = useState(null);
207 var openColorKey = openColorKeyState[0];
208 var setOpenColorKey = openColorKeyState[1];
209
210 var currentStepState = useState(0);
211 var currentStep = currentStepState[0];
212 var setCurrentStep = currentStepState[1];
213
214 var blockProps = useBlockProps({ className: 'bkbg-msf-wrapper', style: buildWrapStyle(a) });
215
216 function cc(key, label, attrKey) {
217 return renderColorControl(key, label, a[attrKey], function (val) {
218 var upd = {}; upd[attrKey] = val; setAttributes(upd);
219 }, openColorKey, setOpenColorKey);
220 }
221
222 function updateStep(stepId, key, val) {
223 setAttributes({ steps: a.steps.map(function (s) {
224 if (s.id !== stepId) return s;
225 var u = Object.assign({}, s); u[key] = val; return u;
226 }) });
227 }
228
229 function updateField(stepId, fieldId, key, val) {
230 setAttributes({ steps: a.steps.map(function (s) {
231 if (s.id !== stepId) return s;
232 return Object.assign({}, s, { fields: s.fields.map(function (f) {
233 if (f.id !== fieldId) return f;
234 var u = Object.assign({}, f); u[key] = val; return u;
235 }) });
236 }) });
237 }
238
239 function addField(stepId) {
240 setAttributes({ steps: a.steps.map(function (s) {
241 if (s.id !== stepId) return s;
242 return Object.assign({}, s, { fields: s.fields.concat([{ id: makeId(), type: 'text', label: __('Field label', 'blockenberg'), placeholder: '', required: false, options: [] }]) });
243 }) });
244 }
245
246 function removeField(stepId, fieldId) {
247 setAttributes({ steps: a.steps.map(function (s) {
248 if (s.id !== stepId) return s;
249 return Object.assign({}, s, { fields: s.fields.filter(function (f) { return f.id !== fieldId; }) });
250 }) });
251 }
252
253 var safeStep = Math.min(currentStep, a.steps.length - 1);
254 var step = a.steps[safeStep];
255 var isLast = safeStep === a.steps.length - 1;
256
257 return el(Fragment, null,
258 el(InspectorControls, null,
259 el(PanelBody, { title: __('Form Settings', 'blockenberg'), initialOpen: true },
260 el(RangeControl, { label: __('Max width (px)', 'blockenberg'), value: a.formMaxWidth, min: 400, max: 900, onChange: function (v) { setAttributes({ formMaxWidth: v }); } }),
261 el(SelectControl, { label: __('Progress style', 'blockenberg'), value: a.progressStyle, options: PROGRESS_STYLE_OPTIONS, onChange: function (v) { setAttributes({ progressStyle: v }); } }),
262 el(ToggleControl, { label: __('Show step titles', 'blockenberg'), checked: a.showStepTitles, onChange: function (v) { setAttributes({ showStepTitles: v }); }, __nextHasNoMarginBottom: true }),
263 el(ToggleControl, { label: __('Show descriptions', 'blockenberg'), checked: a.showStepDescriptions, onChange: function (v) { setAttributes({ showStepDescriptions: v }); }, __nextHasNoMarginBottom: true }),
264 el(ToggleControl, { label: __('Show step numbers', 'blockenberg'), checked: a.showStepNumbers, onChange: function (v) { setAttributes({ showStepNumbers: v }); }, __nextHasNoMarginBottom: true }),
265 el(ToggleControl, { label: __('Show step icons', 'blockenberg'), checked: a.showStepIcons, onChange: function (v) { setAttributes({ showStepIcons: v }); }, __nextHasNoMarginBottom: true })
266 ),
267 el(PanelBody, { title: __('Button Labels', 'blockenberg'), initialOpen: false },
268 el(TextControl, { label: __('Next button', 'blockenberg'), value: a.btnNextLabel, onChange: function (v) { setAttributes({ btnNextLabel: v }); } }),
269 el(TextControl, { label: __('Back button', 'blockenberg'), value: a.btnPrevLabel, onChange: function (v) { setAttributes({ btnPrevLabel: v }); } }),
270 el(TextControl, { label: __('Submit button', 'blockenberg'), value: a.btnSubmitLabel, onChange: function (v) { setAttributes({ btnSubmitLabel: v }); } })
271 ),
272 el(PanelBody, { title: __('Success Screen', 'blockenberg'), initialOpen: false },
273 el(TextControl, { label: __('Title', 'blockenberg'), value: a.successTitle, onChange: function (v) { setAttributes({ successTitle: v }); } }),
274 el(TextareaControl, { label: __('Message', 'blockenberg'), value: a.successMessage, onChange: function (v) { setAttributes({ successMessage: v }); }, rows: 3 })
275 ),
276 el(PanelBody, { title: __('Card & Input Style', 'blockenberg'), initialOpen: false },
277 el(RangeControl, { label: __('Card radius (px)', 'blockenberg'), value: a.cardRadius, min: 0, max: 32, onChange: function (v) { setAttributes({ cardRadius: v }); } }),
278 el(RangeControl, { label: __('Card padding (px)', 'blockenberg'), value: a.cardPadding, min: 16, max: 64, onChange: function (v) { setAttributes({ cardPadding: v }); } }),
279 el(RangeControl, { label: __('Input radius (px)', 'blockenberg'), value: a.inputRadius, min: 0, max: 16, onChange: function (v) { setAttributes({ inputRadius: v }); } }),
280 el(RangeControl, { label: __('Input padding V (px)', 'blockenberg'), value: a.inputPaddingV, min: 6, max: 20, onChange: function (v) { setAttributes({ inputPaddingV: v }); } }),
281 el(RangeControl, { label: __('Button radius (px)', 'blockenberg'), value: a.btnRadius, min: 0, max: 99, onChange: function (v) { setAttributes({ btnRadius: v }); } }),
282 el(RangeControl, { label: __('Step circle (px)', 'blockenberg'), value: a.stepCircleSize, min: 30, max: 64, onChange: function (v) { setAttributes({ stepCircleSize: v }); } })
283 ),
284 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
285 el(getTypoControl(), { label: __('Step Title', 'blockenberg'), value: a.stepTitleTypo, onChange: function (v) { setAttributes({ stepTitleTypo: v }); } }),
286 el(getTypoControl(), { label: __('Step Description', 'blockenberg'), value: a.stepDescTypo, onChange: function (v) { setAttributes({ stepDescTypo: v }); } }),
287 el(RangeControl, { label: __('Step label (px)', 'blockenberg'), value: a.stepLabelSize, min: 10, max: 16, onChange: function (v) { setAttributes({ stepLabelSize: v }); } }),
288 el(RangeControl, { label: __('Field label (px)', 'blockenberg'), value: a.labelSize, min: 12, max: 18, onChange: function (v) { setAttributes({ labelSize: v }); } }),
289 el(RangeControl, { label: __('Input text (px)', 'blockenberg'), value: a.inputSize, min: 13, max: 20, onChange: function (v) { setAttributes({ inputSize: v }); } }),
290 el(RangeControl, { label: __('Button text (px)', 'blockenberg'), value: a.btnSize, min: 13, max: 22, onChange: function (v) { setAttributes({ btnSize: v }); }, __nextHasNoMarginBottom: true })
291 ),
292 el(PanelBody, { title: __('Colors', 'blockenberg'), initialOpen: false },
293 cc('accentColor', __('Accent', 'blockenberg'), 'accentColor'),
294 cc('activeStepBg', __('Active step bg', 'blockenberg'), 'activeStepBg'),
295 cc('activeStepColor', __('Active step icon', 'blockenberg'), 'activeStepColor'),
296 cc('completedStepBg', __('Completed step bg', 'blockenberg'), 'completedStepBg'),
297 cc('completedStepColor', __('Completed step icon', 'blockenberg'), 'completedStepColor'),
298 cc('pendingStepBg', __('Pending step bg', 'blockenberg'), 'pendingStepBg'),
299 cc('pendingStepColor', __('Pending step icon', 'blockenberg'), 'pendingStepColor'),
300 cc('connectorColor', __('Connector line', 'blockenberg'), 'connectorColor'),
301 cc('connectorActiveColor', __('Connector done', 'blockenberg'), 'connectorActiveColor'),
302 cc('stepTitleColor', __('Step title', 'blockenberg'), 'stepTitleColor'),
303 cc('stepDescColor', __('Step desc / labels', 'blockenberg'), 'stepDescColor'),
304 cc('labelColor', __('Field label', 'blockenberg'), 'labelColor'),
305 cc('inputBg', __('Input background', 'blockenberg'), 'inputBg'),
306 cc('inputBorder', __('Input border', 'blockenberg'), 'inputBorder'),
307 cc('inputText', __('Input text', 'blockenberg'), 'inputText'),
308 cc('inputFocusBorder', __('Input focus border', 'blockenberg'), 'inputFocusBorder'),
309 cc('btnBg', __('Primary button bg', 'blockenberg'), 'btnBg'),
310 cc('btnColor', __('Primary button text', 'blockenberg'), 'btnColor'),
311 cc('btnSecBg', __('Secondary button bg', 'blockenberg'), 'btnSecBg'),
312 cc('btnSecColor', __('Secondary button text', 'blockenberg'), 'btnSecColor'),
313 cc('cardBg', __('Card background', 'blockenberg'), 'cardBg'),
314 cc('cardBorderColor', __('Card border', 'blockenberg'), 'cardBorderColor'),
315 cc('bgColor', __('Section background', 'blockenberg'), 'bgColor')
316 ),
317 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
318 el(RangeControl, { label: __('Padding top (px)', 'blockenberg'), value: a.paddingTop, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingTop: v }); } }),
319 el(RangeControl, { label: __('Padding bottom (px)', 'blockenberg'), value: a.paddingBottom, min: 0, max: 200, onChange: function (v) { setAttributes({ paddingBottom: v }); } })
320 ),
321 el(PanelBody, { title: __('Form Steps & Fields', 'blockenberg'), initialOpen: false },
322 a.steps.map(function (s, si) {
323 return el(PanelBody, { key: s.id, title: (s.icon || '📋') + ' ' + (s.title || 'Step ' + (si + 1)), initialOpen: false },
324 el(IP().IconPickerControl, {
325 iconType: s.iconType || 'custom-char',
326 customChar: s.icon || '',
327 dashicon: s.iconDashicon || '',
328 imageUrl: s.iconImageUrl || '',
329 onChangeType: function (v) { updateStep(s.id, 'iconType', v); },
330 onChangeChar: function (v) { updateStep(s.id, 'icon', v); },
331 onChangeDashicon: function (v) { updateStep(s.id, 'iconDashicon', v); },
332 onChangeImageUrl: function (v) { updateStep(s.id, 'iconImageUrl', v); },
333 label: __('Icon', 'blockenberg')
334 }),
335 el(TextControl, { label: __('Step title', 'blockenberg'), value: s.title, onChange: function (v) { updateStep(s.id, 'title', v); } }),
336 el(TextControl, { label: __('Description', 'blockenberg'), value: s.description, onChange: function (v) { updateStep(s.id, 'description', v); } }),
337 el('p', { style: { fontSize: '12px', fontWeight: 600, margin: '8px 0 4px' } }, __('Fields', 'blockenberg')),
338 s.fields.map(function (f, fi) {
339 return el(PanelBody, { key: f.id, title: (f.label || 'Field ' + (fi + 1)) + ' (' + f.type + ')', initialOpen: false },
340 el(SelectControl, { label: __('Field type', 'blockenberg'), value: f.type, options: FIELD_TYPE_OPTIONS, onChange: function (v) { updateField(s.id, f.id, 'type', v); } }),
341 el(TextControl, { label: __('Label', 'blockenberg'), value: f.label, onChange: function (v) { updateField(s.id, f.id, 'label', v); } }),
342 f.type !== 'checkbox' && el(TextControl, { label: __('Placeholder','blockenberg'), value: f.placeholder, onChange: function (v) { updateField(s.id, f.id, 'placeholder', v); } }),
343 (f.type === 'select' || f.type === 'radio') && el(TextareaControl, { label: __('Options (one per line)', 'blockenberg'), value: (f.options || []).join('\n'), onChange: function (v) { updateField(s.id, f.id, 'options', v.split('\n').filter(function (x) { return x.trim(); })); }, rows: 3 }),
344 el(ToggleControl, { label: __('Required', 'blockenberg'), checked: f.required, onChange: function (v) { updateField(s.id, f.id, 'required', v); }, __nextHasNoMarginBottom: true }),
345 el(Button, { onClick: function () { removeField(s.id, f.id); }, isDestructive: true, variant: 'tertiary', size: 'compact', style: { marginTop: '6px' } }, __('Remove field', 'blockenberg'))
346 );
347 }),
348 el(Button, { variant: 'secondary', size: 'compact', onClick: function () { addField(s.id); }, style: { marginTop: '6px' } }, __('+ Add Field', 'blockenberg')),
349 el(Button, { onClick: function () { setAttributes({ steps: a.steps.filter(function (st) { return st.id !== s.id; }) }); setCurrentStep(Math.max(0, safeStep - 1)); }, isDestructive: true, variant: 'tertiary', size: 'compact', style: { marginTop: '6px', display: 'block' } }, __('Remove step', 'blockenberg'))
350 );
351 }),
352 el(Button, { variant: 'primary', onClick: function () { setAttributes({ steps: a.steps.concat([{ id: makeId(), icon: '📝', iconType: 'custom-char', iconDashicon: '', iconImageUrl: '', title: __('New Step', 'blockenberg'), description: '', fields: [] }]) }); }, style: { marginTop: '8px' } }, __('+ Add Step', 'blockenberg'))
353 )
354 ),
355
356 el('div', blockProps,
357 el('div', { className: 'bkbg-msf-outer', style: { maxWidth: a.formMaxWidth + 'px', margin: '0 auto' } },
358 el(StepIndicator, { a: a, currentStep: safeStep, onClickStep: setCurrentStep }),
359 step && el('div', { className: 'bkbg-msf-card', style: { background: a.cardBg, border: '1px solid ' + a.cardBorderColor, borderRadius: a.cardRadius + 'px', padding: a.cardPadding + 'px' } },
360 (a.showStepTitles && step.title) && el('h2', { className: 'bkbg-msf-step-title', style: { margin: '0 0 6px', color: a.stepTitleColor } }, step.title),
361 (a.showStepDescriptions && step.description) && el('p', { className: 'bkbg-msf-step-desc', style: { margin: '0 0 24px', color: a.stepDescColor } }, step.description),
362 step.fields.map(function (f) { return el(FieldPreview, { key: f.id, field: f, a: a }); }),
363 el('div', { className: 'bkbg-msf-nav', style: { display: 'flex', justifyContent: 'space-between', marginTop: '24px', gap: '12px' } },
364 el('div', null,
365 safeStep > 0 && el('button', { type: 'button', onClick: function () { setCurrentStep(safeStep - 1); }, style: { padding: '0 24px', height: (a.btnSize + 20) + 'px', borderRadius: a.btnRadius + 'px', border: '1.5px solid ' + a.cardBorderColor, background: a.btnSecBg, color: a.btnSecColor, cursor: 'pointer', fontSize: a.btnSize + 'px', fontFamily: 'inherit' } }, a.btnPrevLabel)
366 ),
367 el('button', { type: 'button', onClick: function () { if (!isLast && safeStep < a.steps.length - 1) setCurrentStep(safeStep + 1); }, style: { padding: '0 28px', height: (a.btnSize + 20) + 'px', borderRadius: a.btnRadius + 'px', border: 'none', background: a.btnBg, color: a.btnColor, cursor: 'pointer', fontSize: a.btnSize + 'px', fontFamily: 'inherit', fontWeight: 700 } }, isLast ? a.btnSubmitLabel : a.btnNextLabel)
368 )
369 )
370 )
371 )
372 );
373 },
374
375 save: function (props) {
376 var a = props.attributes;
377 return el('div', wp.blockEditor.useBlockProps.save({ className: 'bkbg-msf-wrapper bkbg-msf-progress--' + a.progressStyle, style: buildWrapStyle(a) }),
378 el('div', { className: 'bkbg-msf-outer', style: { maxWidth: a.formMaxWidth + 'px', margin: '0 auto' } },
379 el('div', { className: 'bkbg-msf-indicator', 'data-progress': a.progressStyle, 'data-steps': a.steps.length, 'aria-hidden': 'true' }),
380 el('form', { className: 'bkbg-msf-form', noValidate: true, 'data-current-step': '0', 'data-total-steps': a.steps.length },
381 a.steps.map(function (s, si) {
382 return el('div', { key: s.id, className: 'bkbg-msf-step-panel', 'data-step-idx': si, 'aria-hidden': si === 0 ? 'false' : 'true', style: { display: si === 0 ? 'block' : 'none' } },
383 el('div', { className: 'bkbg-msf-card' },
384 (a.showStepTitles && s.title) && el('h2', { className: 'bkbg-msf-step-title' }, s.title),
385 (a.showStepDescriptions && s.description) && el('p', { className: 'bkbg-msf-step-desc' }, s.description),
386 el('div', { className: 'bkbg-msf-fields' },
387 s.fields.map(function (f) {
388 return el('div', { key: f.id, className: 'bkbg-msf-field', 'data-field-id': f.id },
389 f.type !== 'checkbox' && el('label', { htmlFor: f.id, className: 'bkbg-msf-label' }, f.label, f.required && el('span', { 'aria-hidden': 'true' }, ' *')),
390 f.type === 'textarea' && el('textarea', { id: f.id, name: f.id, className: 'bkbg-msf-input', placeholder: f.placeholder, required: f.required, rows: 3 }),
391 (f.type === 'text' || f.type === 'email' || f.type === 'phone') && el('input', { type: f.type === 'phone' ? 'tel' : f.type, id: f.id, name: f.id, className: 'bkbg-msf-input', placeholder: f.placeholder, required: f.required }),
392 f.type === 'select' && el('select', { id: f.id, name: f.id, className: 'bkbg-msf-input', required: f.required },
393 el('option', { value: '' }, f.placeholder || '— Select —'),
394 (f.options || []).map(function (opt, oi) { return el('option', { key: oi, value: opt }, opt); })
395 ),
396 f.type === 'radio' && el('div', { className: 'bkbg-msf-radio-group' },
397 (f.options || []).map(function (opt, oi) {
398 return el('label', { key: oi, className: 'bkbg-msf-radio-label' },
399 el('input', { type: 'radio', name: f.id, value: opt, required: f.required && oi === 0 }),
400 el('span', null, opt)
401 );
402 })
403 ),
404 f.type === 'checkbox' && el('label', { className: 'bkbg-msf-checkbox-label' },
405 el('input', { type: 'checkbox', name: f.id, required: f.required }),
406 el('span', null, f.label)
407 )
408 );
409 })
410 ),
411 el('div', { className: 'bkbg-msf-nav' },
412 el('button', { type: 'button', className: 'bkbg-msf-btn-prev' + (si === 0 ? ' is-hidden' : ''), 'data-action': 'prev' }, a.btnPrevLabel),
413 el('button', { type: si < a.steps.length - 1 ? 'button' : 'submit', className: 'bkbg-msf-btn-next', 'data-action': si < a.steps.length - 1 ? 'next' : 'submit' }, si < a.steps.length - 1 ? a.btnNextLabel : a.btnSubmitLabel)
414 )
415 )
416 );
417 }),
418 el('div', { className: 'bkbg-msf-success is-hidden', 'aria-live': 'polite' },
419 el('h2', { className: 'bkbg-msf-success-title' }, a.successTitle),
420 el('p', { className: 'bkbg-msf-success-msg' }, a.successMessage)
421 )
422 )
423 )
424 );
425 }
426 });
427 }() );
428