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 / breadcrumbs / index.js

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

286 lines 15.5 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 __ = wp.i18n.__;
5
6 function getTypographyControl() {
7 return (window.bkbgTypographyControl || function () { return null; });
8 }
9
10 function _tv(typo, prefix) {
11 if (!typo) return {};
12 var s = {};
13 if (typo.family) s[prefix + 'font-family'] = "'" + typo.family + "', sans-serif";
14 if (typo.weight) s[prefix + 'font-weight'] = typo.weight;
15 if (typo.transform) s[prefix + 'text-transform'] = typo.transform;
16 if (typo.style) s[prefix + 'font-style'] = typo.style;
17 if (typo.decoration) s[prefix + 'text-decoration'] = typo.decoration;
18 var su = typo.sizeUnit || 'px';
19 if (typo.sizeDesktop !== '' && typo.sizeDesktop != null) s[prefix + 'font-size-d'] = typo.sizeDesktop + su;
20 if (typo.sizeTablet !== '' && typo.sizeTablet != null) s[prefix + 'font-size-t'] = typo.sizeTablet + su;
21 if (typo.sizeMobile !== '' && typo.sizeMobile != null) s[prefix + 'font-size-m'] = typo.sizeMobile + su;
22 var lhu = typo.lineHeightUnit || '';
23 if (typo.lineHeightDesktop !== '' && typo.lineHeightDesktop != null) s[prefix + 'line-height-d'] = typo.lineHeightDesktop + lhu;
24 if (typo.lineHeightTablet !== '' && typo.lineHeightTablet != null) s[prefix + 'line-height-t'] = typo.lineHeightTablet + lhu;
25 if (typo.lineHeightMobile !== '' && typo.lineHeightMobile != null) s[prefix + 'line-height-m'] = typo.lineHeightMobile + lhu;
26 var lsu = typo.letterSpacingUnit || 'px';
27 if (typo.letterSpacingDesktop !== '' && typo.letterSpacingDesktop != null) s[prefix + 'letter-spacing-d'] = typo.letterSpacingDesktop + lsu;
28 if (typo.letterSpacingTablet !== '' && typo.letterSpacingTablet != null) s[prefix + 'letter-spacing-t'] = typo.letterSpacingTablet + lsu;
29 if (typo.letterSpacingMobile !== '' && typo.letterSpacingMobile != null) s[prefix + 'letter-spacing-m'] = typo.letterSpacingMobile + lsu;
30 var wsu = typo.wordSpacingUnit || 'px';
31 if (typo.wordSpacingDesktop !== '' && typo.wordSpacingDesktop != null) s[prefix + 'word-spacing-d'] = typo.wordSpacingDesktop + wsu;
32 if (typo.wordSpacingTablet !== '' && typo.wordSpacingTablet != null) s[prefix + 'word-spacing-t'] = typo.wordSpacingTablet + wsu;
33 if (typo.wordSpacingMobile !== '' && typo.wordSpacingMobile != null) s[prefix + 'word-spacing-m'] = typo.wordSpacingMobile + wsu;
34 return s;
35 }
36
37 var registerBlockType = wp.blocks.registerBlockType;
38 var InspectorControls = wp.blockEditor.InspectorControls;
39 var useBlockProps = wp.blockEditor.useBlockProps;
40 var PanelBody = wp.components.PanelBody;
41 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
42 var ToggleControl = wp.components.ToggleControl;
43 var RangeControl = wp.components.RangeControl;
44 var SelectControl = wp.components.SelectControl;
45 var TextControl = wp.components.TextControl;
46
47 var separatorSVGs = {
48 chevron: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="9 18 15 12 9 6"/></svg>',
49 arrow: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>',
50 slash: null,
51 dot: null,
52 dash: null,
53 custom: null
54 };
55
56 var homeIconSVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>';
57
58 function getSepChar(sep, custom) {
59 if (sep === 'chevron') return '';
60 if (sep === 'arrow') return '';
61 if (sep === 'slash') return '/';
62 if (sep === 'dot') return '·';
63 if (sep === 'dash') return '';
64 return custom || '/';
65 }
66
67 registerBlockType('blockenberg/breadcrumbs', {
68 title: __('Breadcrumbs', 'blockenberg'),
69 description: __('SEO-friendly navigation trail with Schema.org markup.', 'blockenberg'),
70 category: 'bkbg-layout',
71 icon: el('svg', { viewBox: '0 0 24 24', xmlns: 'http://www.w3.org/2000/svg' },
72 el('path', { d: 'M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z', stroke: 'currentColor', strokeWidth: 2, fill: 'none' }),
73 el('polyline', { points: '9 22 9 12 15 12 15 22', stroke: 'currentColor', strokeWidth: 2, fill: 'none' })
74 ),
75 attributes: {
76 homeLabel: { type: 'string', default: 'Home' },
77 homeUrl: { type: 'string', default: '/' },
78 showHome: { type: 'boolean', default: true },
79 showCurrentPage: { type: 'boolean', default: true },
80 separator: { type: 'string', default: 'chevron' },
81 customSeparator: { type: 'string', default: '/' },
82 schemaEnabled: { type: 'boolean', default: true },
83 alignment: { type: 'string', default: 'left' },
84 fontSize: { type: 'number', default: 14 },
85 itemSpacing: { type: 'number', default: 8 },
86 paddingV: { type: 'number', default: 10 },
87 textColor: { type: 'string', default: '#6b7280' },
88 linkColor: { type: 'string', default: '#2563eb' },
89 linkHoverColor: { type: 'string', default: '#1d4ed8' },
90 separatorColor: { type: 'string', default: '#9ca3af' },
91 activeColor: { type: 'string', default: '#111827' },
92 bgColor: { type: 'string', default: '' },
93 fontWeight: { type: 'number', default: 400 },
94 showHomeIcon: { type: 'boolean', default: true },
95 typoText: { type: 'object', default: {} }
96 },
97
98 edit: function (props) {
99 var a = props.attributes;
100 var setAttr = props.setAttributes;
101
102 var blockProps = useBlockProps({
103 className: 'bkbg-bc-wrap bkbg-bc-align--' + a.alignment,
104 style: Object.assign({
105 '--bkbg-bc-gap': a.itemSpacing + 'px',
106 '--bkbg-bc-padv': a.paddingV + 'px',
107 '--bkbg-bc-text': a.textColor,
108 '--bkbg-bc-link': a.linkColor,
109 '--bkbg-bc-hover': a.linkHoverColor,
110 '--bkbg-bc-sep': a.separatorColor,
111 '--bkbg-bc-active': a.activeColor,
112 background: a.bgColor || undefined
113 }, _tv(a.typoText, '--bkbg-bc-typo-'))
114 });
115
116 var inspector = el(InspectorControls, null,
117
118 el(PanelBody, { title: __('Content', 'blockenberg'), initialOpen: true },
119 el(ToggleControl, {
120 label: __('Show Home link', 'blockenberg'),
121 checked: a.showHome,
122 onChange: function(v){ setAttr({ showHome: v }); },
123 __nextHasNoMarginBottom: true
124 }),
125 a.showHome && el(Fragment, null,
126 el(TextControl, {
127 label: __('Home label', 'blockenberg'),
128 value: a.homeLabel,
129 onChange: function(v){ setAttr({ homeLabel: v }); }
130 }),
131 el(TextControl, {
132 label: __('Home URL', 'blockenberg'),
133 value: a.homeUrl,
134 onChange: function(v){ setAttr({ homeUrl: v }); }
135 }),
136 el(ToggleControl, {
137 label: __('Show home icon', 'blockenberg'),
138 checked: a.showHomeIcon,
139 onChange: function(v){ setAttr({ showHomeIcon: v }); },
140 __nextHasNoMarginBottom: true
141 })
142 ),
143 el(ToggleControl, {
144 label: __('Show current page', 'blockenberg'),
145 checked: a.showCurrentPage,
146 onChange: function(v){ setAttr({ showCurrentPage: v }); },
147 __nextHasNoMarginBottom: true
148 }),
149 el(ToggleControl, {
150 label: __('Schema.org markup (BreadcrumbList)', 'blockenberg'),
151 checked: a.schemaEnabled,
152 onChange: function(v){ setAttr({ schemaEnabled: v }); },
153 __nextHasNoMarginBottom: true
154 })
155 ),
156
157 el(PanelBody, { title: __('Separator', 'blockenberg'), initialOpen: false },
158 el(SelectControl, {
159 label: __('Separator style', 'blockenberg'),
160 value: a.separator,
161 options: [
162 { label: 'Chevron ›', value: 'chevron' },
163 { label: 'Arrow →', value: 'arrow' },
164 { label: 'Slash /', value: 'slash' },
165 { label: 'Dot ·', value: 'dot' },
166 { label: 'Dash –', value: 'dash' },
167 { label: 'Custom', value: 'custom' }
168 ],
169 onChange: function(v){ setAttr({ separator: v }); }
170 }),
171 a.separator === 'custom' && el(TextControl, {
172 label: __('Custom separator character', 'blockenberg'),
173 value: a.customSeparator,
174 onChange: function(v){ setAttr({ customSeparator: v }); }
175 })
176 ),
177
178 el(PanelBody, { title: __('Layout', 'blockenberg'), initialOpen: false },
179 el(SelectControl, {
180 label: __('Alignment', 'blockenberg'),
181 value: a.alignment,
182 options: [
183 { label: 'Left', value: 'left' },
184 { label: 'Center', value: 'center' },
185 { label: 'Right', value: 'right' }
186 ],
187 onChange: function(v){ setAttr({ alignment: v }); }
188 }),
189 el(RangeControl, {
190 label: __('Item spacing (px)', 'blockenberg'),
191 value: a.itemSpacing, min: 2, max: 32,
192 onChange: function(v){ setAttr({ itemSpacing: v }); }
193 }),
194 el(RangeControl, {
195 label: __('Vertical padding (px)', 'blockenberg'),
196 value: a.paddingV, min: 0, max: 40,
197 onChange: function(v){ setAttr({ paddingV: v }); }
198 })
199 ),
200
201
202 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
203 el(getTypographyControl(), { label: __('Breadcrumb Text', 'blockenberg'), value: a.typoText, onChange: function (v) { setAttr({ typoText: v }); } })
204 ),
205 el(PanelBody, { title: __('Colors', 'blockenberg'), initialOpen: false },
206 el(PanelColorSettings, {
207 title: __('Colors', 'blockenberg'),
208 initialOpen: false,
209 colorSettings: [
210 { label: __('Background', 'blockenberg'), value: a.bgColor, onChange: function(v){ setAttr({ bgColor: v||'' }); } },
211 { label: __('Link color', 'blockenberg'), value: a.linkColor, onChange: function(v){ setAttr({ linkColor: v||'#2563eb' }); } },
212 { label: __('Link hover', 'blockenberg'), value: a.linkHoverColor,onChange: function(v){ setAttr({ linkHoverColor: v||'#1d4ed8' }); } },
213 { label: __('Current page', 'blockenberg'), value: a.activeColor, onChange: function(v){ setAttr({ activeColor: v||'#111827' }); } },
214 { label: __('Separator', 'blockenberg'), value: a.separatorColor,onChange: function(v){ setAttr({ separatorColor: v||'#9ca3af' }); } },
215 { label: __('Text (general)', 'blockenberg'), value: a.textColor, onChange: function(v){ setAttr({ textColor: v||'#6b7280' }); } }
216 ]
217 })
218 )
219 );
220
221 /* ── Preview breadcrumbs ── */
222 var sepChar = getSepChar(a.separator, a.customSeparator);
223 var crumbs = [];
224 if (a.showHome) {
225 crumbs.push({ label: a.homeLabel, isHome: true, url: a.homeUrl });
226 }
227 crumbs.push({ label: 'Category', url: '#' });
228 crumbs.push({ label: 'Current Page', url: '', isCurrent: true });
229
230 var crumbEls = crumbs.map(function(c, i) {
231 var isLast = i === crumbs.length - 1;
232 return el(Fragment, { key: i },
233 el('span', {
234 className: 'bkbg-bc-item' + (c.isCurrent ? ' bkbg-bc-item--current' : '')
235 },
236 c.isHome && a.showHomeIcon
237 ? el('span', { className: 'bkbg-bc-home-icon', dangerouslySetInnerHTML: { __html: homeIconSVG } })
238 : null,
239 c.url && !c.isCurrent
240 ? el('a', { href: '#', className: 'bkbg-bc-link' }, c.isHome && a.showHomeIcon ? '' : c.label)
241 : (!c.isHome || !a.showHomeIcon) && el('span', { className: 'bkbg-bc-text' }, c.label)
242 ),
243 !isLast && el('span', { className: 'bkbg-bc-sep', 'aria-hidden': 'true' }, sepChar)
244 );
245 });
246
247 return el(Fragment, null,
248 inspector,
249 el('nav', Object.assign({}, blockProps, { 'aria-label': 'Breadcrumb' }),
250 el('ol', { className: 'bkbg-bc-list' }, ...crumbEls)
251 )
252 );
253 },
254
255 save: function (props) {
256 var a = props.attributes;
257 var blockProps = wp.blockEditor.useBlockProps.save({
258 className: 'bkbg-bc-wrap bkbg-bc-align--' + a.alignment,
259 'aria-label': 'Breadcrumb',
260 'data-home-label': a.homeLabel,
261 'data-home-url': a.homeUrl,
262 'data-show-home': a.showHome ? '1' : '0',
263 'data-show-current': a.showCurrentPage ? '1' : '0',
264 'data-separator': a.separator,
265 'data-sep-custom': a.customSeparator,
266 'data-schema': a.schemaEnabled ? '1' : '0',
267 'data-show-icon': a.showHomeIcon ? '1' : '0',
268 style: Object.assign({
269 '--bkbg-bc-gap': a.itemSpacing + 'px',
270 '--bkbg-bc-padv': a.paddingV + 'px',
271 '--bkbg-bc-text': a.textColor,
272 '--bkbg-bc-link': a.linkColor,
273 '--bkbg-bc-hover': a.linkHoverColor,
274 '--bkbg-bc-sep': a.separatorColor,
275 '--bkbg-bc-active': a.activeColor,
276 background: a.bgColor || undefined
277 }, _tv(a.typoText, '--bkbg-bc-typo-'))
278 });
279
280 return el('nav', blockProps,
281 el('ol', { className: 'bkbg-bc-list', 'aria-label': 'breadcrumb' })
282 );
283 }
284 });
285 }() );
286