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

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

169 lines 9.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 __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var useBlockProps = wp.blockEditor.useBlockProps;
7 var RichText = wp.blockEditor.RichText;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var PanelBody = wp.components.PanelBody;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var SelectControl = wp.components.SelectControl;
13 var TextControl = wp.components.TextControl;
14
15 var _tc, _tv;
16 function getTC() { return _tc || (_tc = window.bkbgTypographyControl); }
17 function getTV() { return _tv || (_tv = window.bkbgTypoCssVars); }
18
19 var _IP;
20 function IP() { return _IP || (_IP = window.bkbgIconPicker); }
21
22 var STYLES = [
23 { value: 'bordered', label: 'Bordered (left accent)' },
24 { value: 'filled', label: 'Filled card' },
25 { value: 'minimal', label: 'Minimal (text only)' },
26 { value: 'sticky', label: 'Sticky note' }
27 ];
28
29 var POSITIONS = [
30 { value: 'right', label: 'Float Right' },
31 { value: 'left', label: 'Float Left' },
32 { value: 'inline', label: 'Inline (no float)' }
33 ];
34
35 registerBlockType('blockenberg/sidenote', {
36 edit: function (props) {
37 var attr = props.attributes;
38 var set = props.setAttributes;
39
40 var blockProps = useBlockProps((function () {
41 var _tvf = getTV();
42 var s = { padding: attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px' };
43 if (_tvf) {
44 Object.assign(s, _tvf(attr.labelTypo, '--bksdn-lt-'));
45 Object.assign(s, _tvf(attr.textTypo, '--bksdn-tt-'));
46 }
47 return { style: s };
48 })());
49
50 /* preview wrapper mirrors frontend */
51 var wrapStyle = {
52 width: attr.position === 'inline' ? '100%' : attr.width + 'px',
53 float: attr.position === 'right' ? 'right' : attr.position === 'left' ? 'left' : 'none',
54 margin: attr.position === 'right' ? '4px 0 12px 20px' : attr.position === 'left' ? '4px 20px 12px 0' : '0',
55 boxSizing: 'border-box',
56 background: attr.bgColor,
57 borderRadius: attr.borderRadius + 'px',
58 color: attr.textColor,
59 overflow: 'hidden'
60 };
61
62 if (attr.style === 'bordered' || attr.style === 'filled') {
63 wrapStyle.border = '1px solid ' + attr.borderColor;
64 wrapStyle.padding = '10px 13px';
65 }
66 if (attr.style === 'bordered') {
67 wrapStyle.borderLeft = '4px solid ' + attr.accentColor;
68 }
69 if (attr.style === 'minimal') {
70 wrapStyle.borderLeft = '3px solid ' + attr.accentColor;
71 wrapStyle.paddingLeft = '10px';
72 wrapStyle.background = 'transparent';
73 }
74 if (attr.style === 'sticky') {
75 wrapStyle.border = '1px solid ' + attr.borderColor;
76 wrapStyle.padding = '10px 13px 16px';
77 wrapStyle.boxShadow = '2px 3px 8px rgba(0,0,0,0.10)';
78 }
79
80 var controls = el(InspectorControls, {},
81 el(PanelBody, { title: __('Sidenote', 'blockenberg'), initialOpen: true },
82 el(SelectControl, {
83 label: __('Position', 'blockenberg'), value: attr.position, __nextHasNoMarginBottom: true,
84 options: POSITIONS,
85 onChange: function (v) { set({ position: v }); }
86 }),
87 attr.position !== 'inline' && el('div', { style: { marginTop: '10px' } },
88 el(RangeControl, { label: __('Width (px)', 'blockenberg'), value: attr.width, min: 140, max: 480, __nextHasNoMarginBottom: true, onChange: function (v) { set({ width: v }); } })
89 ),
90 el('div', { style: { marginTop: '10px' } },
91 el(SelectControl, {
92 label: __('Style', 'blockenberg'), value: attr.style, __nextHasNoMarginBottom: true,
93 options: STYLES,
94 onChange: function (v) { set({ style: v }); }
95 })
96 ),
97 el('div', { style: { marginTop: '10px' } },
98 el(ToggleControl, { label: __('Show Label', 'blockenberg'), checked: attr.showLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showLabel: v }); } })
99 ),
100 attr.showLabel && el('div', { style: { marginTop: '6px' } },
101 el(TextControl, { label: __('Label Text', 'blockenberg'), value: attr.label, __nextHasNoMarginBottom: true, onChange: function (v) { set({ label: v }); } })
102 ),
103 el('div', { style: { marginTop: '10px' } },
104 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showIcon: v }); } })
105 ),
106 attr.showIcon && el('div', { style: { marginTop: '6px' } },
107 el(IP().IconPickerControl, IP().iconPickerProps(attr, set))
108 )
109 ),
110 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
111 el(getTC(), { label: 'Label', value: attr.labelTypo, onChange: function (v) { set({ labelTypo: v }); } }),
112 el(getTC(), { label: 'Text', value: attr.textTypo, onChange: function (v) { set({ textTypo: v }); } })
113 ),
114 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
115 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } }),
116 el('div', { style: { marginTop: '10px' } },
117 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 60, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
118 ),
119 el('div', { style: { marginTop: '10px' } },
120 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 60, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
121 )
122 ),
123 el(PanelColorSettings, {
124 title: __('Colors', 'blockenberg'), initialOpen: false,
125 colorSettings: [
126 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#fffbeb' }); } },
127 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#fbbf24' }); } },
128 { label: __('Accent / Left Strip', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#d97706' }); } },
129 { label: __('Label', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#92400e' }); } },
130 { label: __('Text', 'blockenberg'), value: attr.textColor, onChange: function (v) { set({ textColor: v || '#78350f' }); } },
131 { label: __('Icon', 'blockenberg'), value: attr.iconColor, onChange: function (v) { set({ iconColor: v || '#d97706' }); } }
132 ]
133 })
134 );
135
136 var labelRow = (attr.showLabel || attr.showIcon) && el('div', { className: 'bkbg-sdn-label-row', style: { display: 'flex', alignItems: 'center', gap: '5px', marginBottom: '5px' } },
137 attr.showIcon && IP().buildEditorIcon(attr.iconType, attr.icon, attr.iconDashicon, attr.iconImageUrl, { dashiconColor: attr.iconDashiconColor, className: 'bkbg-sdn-icon', style: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', lineHeight: 1, color: attr.iconColor, fontSize: '14px' } }),
138 attr.showLabel && el('span', { className: 'bkbg-sdn-label', style: { color: attr.labelColor } }, attr.label)
139 );
140
141 var textEl = el(RichText, {
142 tagName: 'p',
143 className: 'bkbg-sdn-text',
144 value: attr.text,
145 allowedFormats: ['core/bold', 'core/italic', 'core/link'],
146 placeholder: __('Side note or annotation text…', 'blockenberg'),
147 style: { margin: 0, color: attr.textColor },
148 onChange: function (v) { set({ text: v }); }
149 });
150
151 return el('div', blockProps,
152 controls,
153 el('div', { style: wrapStyle },
154 labelRow,
155 textEl
156 ),
157 attr.position !== 'inline' && el('div', { style: { clear: 'both', height: 0 } })
158 );
159 },
160 save: function (props) {
161 var attr = props.attributes;
162 var useBlockProps = wp.blockEditor.useBlockProps;
163 return el('div', useBlockProps.save(),
164 el('div', { className: 'bkbg-sdn-app', 'data-opts': JSON.stringify(attr) })
165 );
166 }
167 });
168 }() );
169