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

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/kinetic-text/index.js

186 lines 8.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 useBlockProps = wp.blockEditor.useBlockProps;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var RichText = wp.blockEditor.RichText;
9 var PanelBody = wp.components.PanelBody;
10 var RangeControl = wp.components.RangeControl;
11 var SelectControl = wp.components.SelectControl;
12
13 var _tc, _tv;
14 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
15 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
16
17 function EditorPreview(props) {
18 var a = props.attributes;
19 /* Split text into character spans */
20 var chars = (a.text || '').split('').map(function (ch, i) {
21 return el('span', {
22 key: i,
23 className: 'bkbg-kt-char',
24 style: { color: a.textColor || '#0f172a' }
25 }, ch === ' ' ? '\u00a0' : ch);
26 });
27
28 return el(a.tag || 'h2', {
29 className: 'bkbg-kt-text',
30 style: {
31 textAlign: a.textAlign || 'center',
32 userSelect: 'none',
33 cursor: 'default'
34 }
35 }, chars);
36 }
37
38 registerBlockType('blockenberg/kinetic-text', {
39 title: __('Kinetic Text'),
40 icon: 'editor-spellcheck',
41 category: 'bkbg-effects',
42
43 edit: function (props) {
44 var attr = props.attributes;
45 var setAttr = props.setAttributes;
46 var bp = useBlockProps((function () {
47 var _tvFn = getTypoCssVars();
48 var s = {
49 background: attr.bgColor || 'transparent',
50 padding: '32px 16px',
51 textAlign: attr.textAlign || 'center'
52 };
53 if (_tvFn) Object.assign(s, _tvFn(attr.textTypo, '--bkbg-kt-tx-'));
54 return { className: 'bkbg-kt-wrap', style: s };
55 })());
56
57 var inspector = el(InspectorControls, {},
58 el(PanelBody, { title: __('Text'), initialOpen: true },
59 el(RichText, {
60 tagName: 'span',
61 value: attr.text,
62 onChange: function (v) { setAttr({ text: v.replace(/<[^>]*>/g, '') }); },
63 placeholder: __('Type your text…'),
64 __nextHasNoMarginBottom: true
65 }),
66 el(SelectControl, {
67 label: __('HTML Tag'),
68 value: attr.tag,
69 options: [
70 { label: 'H1', value: 'h1' },
71 { label: 'H2', value: 'h2' },
72 { label: 'H3', value: 'h3' },
73 { label: 'H4', value: 'h4' },
74 { label: 'p', value: 'p' },
75 { label: 'div', value: 'div' }
76 ],
77 onChange: function (v) { setAttr({ tag: v }); },
78 __nextHasNoMarginBottom: true
79 }),
80 el(SelectControl, {
81 label: __('Text Align'),
82 value: attr.textAlign,
83 options: [
84 { label: __('Left'), value: 'left' },
85 { label: __('Center'), value: 'center' },
86 { label: __('Right'), value: 'right' }
87 ],
88 onChange: function (v) { setAttr({ textAlign: v }); },
89 __nextHasNoMarginBottom: true
90 }),
91 ),
92
93 el(PanelBody, { title: __('Scatter Effect'), initialOpen: false },
94 el(SelectControl, {
95 label: __('Trigger'),
96 value: attr.trigger,
97 options: [
98 { label: __('On Hover'), value: 'hover' },
99 { label: __('On Click'), value: 'click' },
100 { label: __('Auto Loop'), value: 'auto' }
101 ],
102 onChange: function (v) { setAttr({ trigger: v }); },
103 __nextHasNoMarginBottom: true
104 }),
105 el(SelectControl, {
106 label: __('Scatter Mode'),
107 value: attr.scatterMode,
108 options: [
109 { label: __('Explode Outward'), value: 'explode' },
110 { label: __('Rain Down'), value: 'rain' },
111 { label: __('Spin & Scatter'), value: 'spin' },
112 { label: __('Float Up'), value: 'float' }
113 ],
114 onChange: function (v) { setAttr({ scatterMode: v }); },
115 __nextHasNoMarginBottom: true
116 }),
117 el(RangeControl, { label: __('Scatter Radius (px)'), value: attr.scatterRadius,
118 min: 40, max: 400,
119 onChange: function (v) { setAttr({ scatterRadius: v }); },
120 __nextHasNoMarginBottom: true }),
121 el(RangeControl, { label: __('Scatter Duration (ms)'), value: attr.scatterDuration,
122 min: 100, max: 1000, step: 50,
123 onChange: function (v) { setAttr({ scatterDuration: v }); },
124 __nextHasNoMarginBottom: true }),
125 el(RangeControl, { label: __('Return Duration (ms)'), value: attr.returnDuration,
126 min: 100, max: 1500, step: 50,
127 onChange: function (v) { setAttr({ returnDuration: v }); },
128 __nextHasNoMarginBottom: true }),
129 el(RangeControl, { label: __('Stagger Delay (ms)'), value: attr.stagger,
130 min: 0, max: 100, step: 5,
131 onChange: function (v) { setAttr({ stagger: v }); },
132 __nextHasNoMarginBottom: true })
133 ),
134
135
136 el( PanelBody, { title: __( 'Typography', 'blockenberg' ), initialOpen: false },
137 getTypoControl() && el(getTypoControl(), { label: __('Text'), value: attr.textTypo || {}, onChange: function (v) { setAttr({ textTypo: v }); } })
138 ),
139 el(PanelColorSettings, {
140 title: __('Colors'), initialOpen: false,
141 colorSettings: [
142 { label: __('Text Color'), value: attr.textColor,
143 onChange: function (v) { setAttr({ textColor: v || '#0f172a' }); } },
144 { label: __('Hover Color'), value: attr.hoverColor,
145 onChange: function (v) { setAttr({ hoverColor: v || '#6366f1' }); } },
146 { label: __('Background'), value: attr.bgColor,
147 onChange: function (v) { setAttr({ bgColor: v || 'transparent' }); } }
148 ]
149 })
150 );
151
152 return el(wp.element.Fragment, {}, inspector,
153 el('div', bp,
154 el(EditorPreview, { attributes: attr })
155 )
156 );
157 },
158
159 save: function (props) {
160 var attr = props.attributes;
161 var bp = useBlockProps.save();
162 var opts = {
163 text: attr.text,
164 tag: attr.tag,
165 trigger: attr.trigger,
166 scatterMode: attr.scatterMode,
167 scatterRadius: attr.scatterRadius,
168 scatterDuration: attr.scatterDuration,
169 returnDuration: attr.returnDuration,
170 stagger: attr.stagger,
171 fontSize: attr.fontSize,
172 fontWeight: attr.fontWeight,
173 letterSpacing: attr.letterSpacing,
174 textAlign: attr.textAlign,
175 textColor: attr.textColor,
176 textTypo: attr.textTypo,
177 hoverColor: attr.hoverColor,
178 bgColor: attr.bgColor
179 };
180 return el('div', bp,
181 el('div', { className: 'bkbg-kt-app', 'data-opts': JSON.stringify(opts) })
182 );
183 }
184 });
185 }() );
186