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

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

181 lines 7.7 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 RichText = wp.blockEditor.RichText;
7 var PanelBody = wp.components.PanelBody;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
9 var SelectControl = wp.components.SelectControl;
10 var ToggleControl = wp.components.ToggleControl;
11 var RangeControl = wp.components.RangeControl;
12 var TextControl = wp.components.TextControl;
13
14 var _tc; function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
15 var _tv; function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
16
17 var PRESETS = {
18 yellow: { note: '#fef08a', text: '#333' },
19 pink: { note: '#fce7f3', text: '#831843' },
20 green: { note: '#bbf7d0', text: '#14532d' },
21 blue: { note: '#bfdbfe', text: '#1e3a5f' },
22 orange: { note: '#fed7aa', text: '#7c2d12' },
23 custom: null
24 };
25
26 registerBlockType( 'blockenberg/sticky-note', {
27 edit: function ( props ) {
28 var attrs = props.attributes;
29 var setAttr = props.setAttributes;
30
31 var noteColor = attrs.preset !== 'custom' && PRESETS[ attrs.preset ]
32 ? PRESETS[ attrs.preset ].note : attrs.noteColor;
33 var textColor = attrs.preset !== 'custom' && PRESETS[ attrs.preset ]
34 ? PRESETS[ attrs.preset ].text : attrs.textColor;
35
36 var _tvf = getTypoCssVars();
37 var wrapStyle = {
38 '--bksn-bg': noteColor,
39 '--bksn-text': textColor,
40 '--bksn-w': attrs.width + 'px',
41 '--bksn-p': attrs.padding + 'px',
42 '--bksn-fs': attrs.fontSize + 'px',
43 '--bksn-fw': attrs.fontWeight,
44 '--bksn-lh': attrs.lineHeight,
45 '--bksn-rot': attrs.rotated ? attrs.rotationDeg + 'deg' : '0deg',
46 '--bksn-shadow': attrs.shadow ? '4px 6px 16px rgba(0,0,0,.2)' : 'none'
47 };
48 Object.assign(wrapStyle, _tvf(attrs.headingTypo, '--bksn-hd-'));
49 Object.assign(wrapStyle, _tvf(attrs.textTypo, '--bksn-tx-'));
50
51 var classes = [
52 'bksn-wrap',
53 attrs.handwrittenFont ? 'bksn-handwritten' : '',
54 attrs.curlCorner ? 'bksn-curl' : ''
55 ].filter(Boolean).join( ' ' );
56
57 return el( 'div', null,
58 el( InspectorControls, null,
59 el( PanelBody, { title: __( 'Note Style', 'blockenberg' ), initialOpen: true },
60 el( SelectControl, {
61 label: __( 'Color Preset', 'blockenberg' ),
62 value: attrs.preset,
63 options: [
64 { label: 'Yellow', value: 'yellow' },
65 { label: 'Pink', value: 'pink' },
66 { label: 'Green', value: 'green' },
67 { label: 'Blue', value: 'blue' },
68 { label: 'Orange', value: 'orange' },
69 { label: 'Custom', value: 'custom' }
70 ],
71 onChange: function (v) { setAttr({ preset: v }); }
72 } ),
73 el( ToggleControl, {
74 label: __( 'Rotate Note', 'blockenberg' ),
75 checked: attrs.rotated,
76 onChange: function (v) { setAttr({ rotated: v }); },
77 __nextHasNoMarginBottom: true
78 } ),
79 attrs.rotated && el( RangeControl, {
80 label: __( 'Rotation (degrees)', 'blockenberg' ),
81 value: attrs.rotationDeg, min: -10, max: 10,
82 onChange: function (v) { setAttr({ rotationDeg: v }); }
83 } ),
84 el( ToggleControl, {
85 label: __( 'Handwritten Font', 'blockenberg' ),
86 checked: attrs.handwrittenFont,
87 onChange: function (v) { setAttr({ handwrittenFont: v }); },
88 __nextHasNoMarginBottom: true
89 } ),
90 el( ToggleControl, {
91 label: __( 'Curl Corner', 'blockenberg' ),
92 checked: attrs.curlCorner,
93 onChange: function (v) { setAttr({ curlCorner: v }); },
94 __nextHasNoMarginBottom: true
95 } ),
96 el( ToggleControl, {
97 label: __( 'Shadow', 'blockenberg' ),
98 checked: attrs.shadow,
99 onChange: function (v) { setAttr({ shadow: v }); },
100 __nextHasNoMarginBottom: true
101 } ),
102 el( RangeControl, {
103 label: __( 'Width (px)', 'blockenberg' ),
104 value: attrs.width, min: 120, max: 500,
105 onChange: function (v) { setAttr({ width: v }); }
106 } ),
107 el( RangeControl, {
108 label: __( 'Padding (px)', 'blockenberg' ),
109 value: attrs.padding, min: 10, max: 40,
110 onChange: function (v) { setAttr({ padding: v }); }
111 } ),
112 ),
113 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
114 getTypoControl() && getTypoControl()({ label: __('Heading', 'blockenberg'), value: attrs.headingTypo, onChange: function (v) { setAttr({ headingTypo: v }); } }),
115 getTypoControl() && getTypoControl()({ label: __('Text', 'blockenberg'), value: attrs.textTypo, onChange: function (v) { setAttr({ textTypo: v }); } })
116 ),
117 el( PanelBody, { title: __( 'Custom Colors', 'blockenberg' ), initialOpen: false },
118 el( PanelColorSettings, {
119 title: __( 'Colors', 'blockenberg' ),
120 colorSettings: [
121 { value: attrs.noteColor, onChange: function(v){setAttr({noteColor:v||'#fef08a'});}, label: __('Note Background') },
122 { value: attrs.textColor, onChange: function(v){setAttr({textColor:v||'#333'});}, label: __('Text') }
123 ]
124 } )
125 )
126 ),
127 el( 'div', { className: classes, style: wrapStyle },
128 attrs.headingText && el( RichText, {
129 tagName: 'strong',
130 className: 'bksn-heading',
131 value: attrs.headingText,
132 onChange: function (v) { setAttr({ headingText: v }); },
133 placeholder: __( 'Heading (optional)…', 'blockenberg' )
134 } ),
135 el( RichText, {
136 tagName: 'p',
137 className: 'bksn-text',
138 value: attrs.text,
139 onChange: function (v) { setAttr({ text: v }); },
140 placeholder: __( 'Note text…', 'blockenberg' )
141 } )
142 )
143 );
144 },
145 save: function ( props ) {
146 var attrs = props.attributes;
147 var noteColor = attrs.preset !== 'custom' && PRESETS[ attrs.preset ]
148 ? PRESETS[ attrs.preset ].note : attrs.noteColor;
149 var textColor = attrs.preset !== 'custom' && PRESETS[ attrs.preset ]
150 ? PRESETS[ attrs.preset ].text : attrs.textColor;
151 var classes = [
152 'bksn-wrap',
153 attrs.handwrittenFont ? 'bksn-handwritten' : '',
154 attrs.curlCorner ? 'bksn-curl' : ''
155 ].filter(Boolean).join( ' ' );
156 var _tvf2 = getTypoCssVars();
157 var saveStyle = {
158 '--bksn-bg': noteColor,
159 '--bksn-text': textColor,
160 '--bksn-w': attrs.width + 'px',
161 '--bksn-p': attrs.padding + 'px',
162 '--bksn-fs': attrs.fontSize + 'px',
163 '--bksn-fw': attrs.fontWeight,
164 '--bksn-lh': attrs.lineHeight,
165 '--bksn-rot': attrs.rotated ? attrs.rotationDeg + 'deg' : '0deg',
166 '--bksn-shadow': attrs.shadow ? '4px 6px 16px rgba(0,0,0,.2)' : 'none'
167 };
168 Object.assign(saveStyle, _tvf2(attrs.headingTypo, '--bksn-hd-'));
169 Object.assign(saveStyle, _tvf2(attrs.textTypo, '--bksn-tx-'));
170 return el( 'div', {
171 className: classes,
172 style: saveStyle
173 },
174 attrs.headingText && el( RichText.Content, { tagName: 'strong', className: 'bksn-heading', value: attrs.headingText } ),
175 el( RichText.Content, { tagName: 'p', className: 'bksn-text', value: attrs.text } )
176 );
177 }
178 } );
179
180 } )();
181