PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.14
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.14
2.0.14 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 / unfold / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.14, at blocks/unfold/index.js

208 lines 11.1 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 registerBlockType = wp.blocks.registerBlockType;
4 var useBlockProps = wp.blockEditor.useBlockProps;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
7 var RichText = wp.blockEditor.RichText;
8 var PanelBody = wp.components.PanelBody;
9 var RangeControl = wp.components.RangeControl;
10 var ToggleControl = wp.components.ToggleControl;
11 var SelectControl = wp.components.SelectControl;
12 var TextControl = wp.components.TextControl;
13
14 // Resolve the shared components lazily without defining globals for each block.
15 function _tc(label, key, attrs, setA) {
16 var Control = window.bkbgTypographyControl;
17 return Control ? el(Control, {
18 label: label,
19 value: attrs[key] || {},
20 onChange: function (value) { var update = {}; update[key] = value; setA(update); }
21 }) : null;
22 }
23 function _tvf(vars, key, attrs, prefix) {
24 var cssVars = window.bkbgTypoCssVars;
25 if (cssVars) Object.assign(vars, cssVars(attrs[key] || {}, prefix));
26 return vars;
27 }
28 function getTypoControl(label, key, attrs, setA) { return _tc(label, key, attrs, setA); }
29 function getTypoCssVars(attrs) {
30 var v = {};
31 _tvf(v, 'contentTypo', attrs, '--bkufd-ct-');
32 _tvf(v, 'buttonTypo', attrs, '--bkufd-bt-');
33 return v;
34 }
35
36 registerBlockType('blockenberg/unfold', {
37 edit: function (props) {
38 var a = props.attributes;
39 var set = props.setAttributes;
40 var blockProps = useBlockProps((function () { var _tv = getTypoCssVars(a); var s = {}; Object.assign(s, _tv); return { style: s }; })());
41
42 var btnStyle = {};
43 if (a.buttonStyle === 'filled') {
44 btnStyle = {
45 background: a.buttonBg || '#6366f1',
46 color: a.buttonColor || '#ffffff',
47 border: 'none',
48 borderRadius: (a.borderRadius || 8) + 'px',
49 padding: '10px 24px',
50 cursor: 'pointer',
51 transition: 'opacity .2s, transform .15s',
52 display: 'inline-block'
53 };
54 } else if (a.buttonStyle === 'outline') {
55 btnStyle = {
56 background: 'transparent',
57 color: a.accentColor || '#6366f1',
58 border: '2px solid ' + (a.accentColor || '#6366f1'),
59 borderRadius: (a.borderRadius || 8) + 'px',
60 padding: '10px 24px',
61 cursor: 'pointer',
62 display: 'inline-block'
63 };
64 } else { // text
65 btnStyle = {
66 background: 'none',
67 border: 'none',
68 color: a.accentColor || '#6366f1',
69 cursor: 'pointer',
70 padding: '4px 0',
71 display: 'inline-block'
72 };
73 }
74
75 return el('div', blockProps,
76 el(InspectorControls, {},
77 el(PanelBody, { title: 'Content', initialOpen: true },
78 el(RangeControl, { label: 'Preview height (px)', value: a.previewHeight || 200,
79 onChange: function (v) { set({ previewHeight: v }); }, min: 60, max: 800, __nextHasNoMarginBottom: true }),
80 el(RangeControl, { label: 'Fade gradient height (px)', value: a.gradientHeight || 60,
81 onChange: function (v) { set({ gradientHeight: v }); }, min: 20, max: 200, __nextHasNoMarginBottom: true }),
82 el(RangeControl, { label: 'Expand animation (ms)', value: a.animationDuration || 400,
83 onChange: function (v) { set({ animationDuration: v }); }, min: 100, max: 1200, step: 50, __nextHasNoMarginBottom: true })
84 ),
85 el(PanelBody, { title: 'Button Settings', initialOpen: false },
86 el(TextControl, { label: 'Expand button text', value: a.expandText || '',
87 onChange: function (v) { set({ expandText: v }); }, __nextHasNoMarginBottom: true }),
88 el(TextControl, { label: 'Collapse button text', value: a.collapseText || '',
89 onChange: function (v) { set({ collapseText: v }); }, __nextHasNoMarginBottom: true }),
90 el(ToggleControl, { label: 'Show collapse button', checked: a.showCollapseBtn !== false,
91 onChange: function (v) { set({ showCollapseBtn: v }); }, __nextHasNoMarginBottom: true }),
92 el(SelectControl, { label: 'Button alignment', value: a.buttonAlign || 'center',
93 options: [
94 { label: 'Left', value: 'left' },
95 { label: 'Center', value: 'center' },
96 { label: 'Right', value: 'right' }
97 ],
98 onChange: function (v) { set({ buttonAlign: v }); }, __nextHasNoMarginBottom: true }),
99 el(SelectControl, { label: 'Button style', value: a.buttonStyle || 'filled',
100 options: [
101 { label: 'Filled', value: 'filled' },
102 { label: 'Outline', value: 'outline' },
103 { label: 'Text', value: 'text' }
104 ],
105 onChange: function (v) { set({ buttonStyle: v }); }, __nextHasNoMarginBottom: true }),
106 el(RangeControl, { label: 'Border radius', value: a.borderRadius || 8,
107 onChange: function (v) { set({ borderRadius: v }); }, min: 0, max: 40, __nextHasNoMarginBottom: true })
108 ),
109
110 el( PanelBody, { title: 'Typography', initialOpen: false },
111 getTypoControl('Content', 'contentTypo', a, set),
112 getTypoControl('Button', 'buttonTypo', a, set)
113 ),
114 el(PanelColorSettings, {
115 title: 'Colors', initialOpen: false,
116 colorSettings: [
117 { label: 'Section background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#ffffff' }); } },
118 { label: 'Content text', value: a.contentColor, onChange: function (v) { set({ contentColor: v || '#374151' }); } },
119 { label: 'Gradient end color', value: a.gradientTo, onChange: function (v) { set({ gradientTo: v || '#ffffff' }); } },
120 { label: 'Accent / focus', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#6366f1' }); } },
121 { label: 'Button background', value: a.buttonBg, onChange: function (v) { set({ buttonBg: v || '#6366f1' }); } },
122 { label: 'Button text', value: a.buttonColor, onChange: function (v) { set({ buttonColor: v || '#ffffff' }); } }
123 ],
124 disableCustomGradients: true
125 })
126 ),
127
128 // Editor preview
129 el('div', {
130 style: {
131 background: a.sectionBg || '#ffffff',
132 padding: '24px',
133 borderRadius: (a.borderRadius || 8) + 'px',
134 border: '1px solid #e5e7eb'
135 }
136 },
137 // Content area (limited height visually)
138 el('div', {
139 className: 'bkbg-ufd-content-body',
140 style: {
141 position: 'relative',
142 maxHeight: (a.previewHeight || 200) + 'px',
143 overflow: 'hidden',
144 color: a.contentColor || '#374151'
145 }
146 },
147 el(RichText, {
148 tagName: 'div',
149 value: a.content,
150 onChange: function (v) { set({ content: v }); },
151 placeholder: 'Write your expandable content here…',
152 multiline: 'p'
153 }),
154 // Gradient overlay
155 el('div', {
156 style: {
157 position: 'absolute',
158 bottom: 0, left: 0, right: 0,
159 height: (a.gradientHeight || 60) + 'px',
160 background: 'linear-gradient(transparent, ' + (a.gradientTo || '#ffffff') + ')',
161 pointerEvents: 'none'
162 }
163 })
164 ),
165 // Button row
166 el('div', {
167 style: {
168 textAlign: a.buttonAlign || 'center',
169 marginTop: 16
170 }
171 },
172 el('span', { className: 'bkbg-ufd-btn', style: btnStyle }, a.expandText || 'Read More ↓')
173 )
174 )
175 );
176 },
177
178 save: function (props) {
179 var a = props.attributes;
180 var blockProps = useBlockProps.save((function () { var _tv = getTypoCssVars(a); var s = {}; Object.assign(s, _tv); return { style: s }; })());
181 var opts = {
182 previewHeight: a.previewHeight || 200,
183 expandText: a.expandText || 'Read More ↓',
184 collapseText: a.collapseText || 'Show Less ↑',
185 showCollapseBtn: a.showCollapseBtn !== false,
186 gradientHeight: a.gradientHeight || 60,
187 animationDuration: a.animationDuration || 400,
188 buttonAlign: a.buttonAlign || 'center',
189 buttonStyle: a.buttonStyle || 'filled',
190 borderRadius: a.borderRadius || 8,
191 sectionBg: a.sectionBg || '#ffffff',
192 contentColor: a.contentColor || '#374151',
193 gradientTo: a.gradientTo || '#ffffff',
194 accentColor: a.accentColor || '#6366f1',
195 buttonBg: a.buttonBg || '#6366f1',
196 buttonColor: a.buttonColor || '#ffffff'
197 };
198 return el('div', blockProps,
199 el('div', { className: 'bkbg-ufd-app', 'data-opts': JSON.stringify(opts) },
200 el('div', { className: 'bkbg-ufd-content-src' },
201 el(RichText.Content, { tagName: 'div', value: a.content, multiline: 'p' })
202 )
203 )
204 );
205 }
206 });
207 }() );
208