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

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

126 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var el = window.wp.element.createElement;
3 var { registerBlockType } = window.wp.blocks;
4 var { InspectorControls, PanelColorSettings } = window.wp.blockEditor;
5 var { PanelBody, RangeControl, SelectControl, TextControl, TextareaControl, ToggleControl } = window.wp.components;
6 var { __ } = window.wp.i18n;
7
8 // Resolve the shared components lazily without defining globals for each block.
9 function _tc(props, key, label) {
10 var Control = window.bkbgTypographyControl;
11 return Control ? el(Control, {
12 label: label,
13 value: props.attributes[key] || {},
14 onChange: function (value) { var update = {}; update[key] = value; props.setAttributes(update); }
15 }) : null;
16 }
17 function _tvf(typo, prefix) {
18 var cssVars = window.bkbgTypoCssVars;
19 return cssVars ? cssVars(typo || {}, prefix) : {};
20 }
21 function getTypoControl(p, key, label) { return _tc ? _tc(p, key, label) : null; }
22 function getTypoCssVars(a) {
23 if (!_tvf) return {};
24 return _tvf(a.textTypo || {}, '--bkte-tx-');
25 }
26
27 var TAGS = ['h1','h2','h3','h4','p','div'].map(t=>({label:t.toUpperCase(),value:t}));
28 var ALIGNS = [{label:'Left',value:'left'},{label:'Center',value:'center'},{label:'Right',value:'right'}];
29
30 registerBlockType('blockenberg/typing-effect', {
31 edit: function(props) {
32 var a = props.attributes;
33 var set = props.setAttributes;
34 var phrases = (a.phrases||'').split(',').map(s=>s.trim()).filter(Boolean);
35
36 var wrapStyle = (function () {
37 var _tv = getTypoCssVars(a);
38 var s = {
39 background: a.bgColor || undefined,
40 paddingTop: a.paddingTop + 'px',
41 paddingBottom: a.paddingBottom + 'px',
42 textAlign: a.textAlign,
43 };
44 Object.assign(s, _tv);
45 return s;
46 })();
47
48 return el('div', { className: 'bkte-wrap', style: wrapStyle },
49 el(InspectorControls, null,
50 el(PanelBody, { title: __('Content'), initialOpen: true },
51 el(TextControl, { label: __('Static Prefix Text'), value: a.prefix, onChange: v => set({prefix:v}) }),
52 el(TextareaControl, { label: __('Typing Phrases (comma-separated)'), value: a.phrases, rows: 4,
53 help: __('e.g.: beautiful websites,powerful apps,amazing brands'),
54 onChange: v => set({phrases:v}) }),
55 el(TextControl, { label: __('Static Suffix Text'), value: a.suffix, onChange: v => set({suffix:v}) }),
56 el(SelectControl, { label: __('HTML Tag'), value: a.tag, options: TAGS, onChange: v => set({tag:v}) }),
57 ),
58 el(PanelBody, { title: __('Animation'), initialOpen: false },
59 el(RangeControl, { label: __('Type Speed (ms/char)'), value: a.typeSpeed, min:20, max:300, onChange: v=>set({typeSpeed:v}) }),
60 el(RangeControl, { label: __('Delete Speed (ms/char)'), value: a.deleteSpeed, min:10, max:200, onChange: v=>set({deleteSpeed:v}) }),
61 el(RangeControl, { label: __('Pause After Phrase (ms)'), value: a.pauseDelay, min:200, max:5000, step:100, onChange: v=>set({pauseDelay:v}) }),
62 el(ToggleControl, { label: __('Loop'), checked: a.loop, onChange:v=>set({loop:v}), __nextHasNoMarginBottom:true }),
63 el(TextControl, { label: __('Cursor Character'), value: a.cursorChar, onChange: v=>set({cursorChar:v.slice(0,2)}) }),
64 el(ToggleControl, { label: __('Cursor Blink'), checked: a.cursorBlink, onChange:v=>set({cursorBlink:v}), __nextHasNoMarginBottom:true }),
65 ),
66 el(PanelBody, { title: __('Typography'), initialOpen: false },
67 getTypoControl(props, 'textTypo', __('Text')),
68 el(SelectControl, { label: __('Text Align'), value: a.textAlign, options: ALIGNS, onChange: v=>set({textAlign:v}) }),
69 ),
70 el(PanelBody, { title: __('Spacing'), initialOpen: false },
71 el(RangeControl, { label: __('Padding Top (px)'), value: a.paddingTop, min:0, max:200, onChange: v=>set({paddingTop:v}) }),
72 el(RangeControl, { label: __('Padding Bottom (px)'), value: a.paddingBottom, min:0, max:200, onChange: v=>set({paddingBottom:v}) }),
73 ),
74 el(PanelColorSettings, { title: __('Colors'), initialOpen: false, colorSettings: [
75 { label: __('Prefix / Suffix Color'), value: a.prefixColor, onChange: v=>set({prefixColor:v||'#1f2937'}) },
76 { label: __('Typed Text Color'), value: a.typedColor, onChange: v=>set({typedColor:v||'#6c3fb5'}) },
77 { label: __('Cursor Color'), value: a.cursorColor, onChange: v=>set({cursorColor:v||'#6c3fb5'}) },
78 { label: __('Background Color'), value: a.bgColor, onChange: v=>set({bgColor:v||''}) },
79 ]}),
80 ),
81
82 el(a.tag||'h2', { className: 'bkte-text', style: {
83 textAlign: a.textAlign, margin: 0,
84 }},
85 a.prefix && el('span', { className:'bkte-prefix', style:{color:a.prefixColor} }, a.prefix),
86 el('span', { className:'bkte-typed', style:{color:a.typedColor} }, phrases[0]||''),
87 el('span', { className:'bkte-cursor bkte-cursor-blink', style:{color:a.cursorColor} }, a.cursorChar||'|'),
88 a.suffix && el('span', { className:'bkte-suffix', style:{color:a.prefixColor} }, a.suffix),
89 ),
90 );
91 },
92
93 save: function({attributes:a}) {
94 var wrapStyle = (function () {
95 var _tv = getTypoCssVars(a);
96 var s = {
97 background: a.bgColor || undefined,
98 paddingTop: a.paddingTop + 'px',
99 paddingBottom: a.paddingBottom + 'px',
100 textAlign: a.textAlign,
101 };
102 Object.assign(s, _tv);
103 return s;
104 })();
105 return el('div', {
106 className: 'bkte-wrap', style: wrapStyle,
107 'data-phrases': a.phrases,
108 'data-type-speed': a.typeSpeed,
109 'data-delete-speed': a.deleteSpeed,
110 'data-pause': a.pauseDelay,
111 'data-loop': a.loop ? '1' : '0',
112 'data-cursor-blink': a.cursorBlink ? '1' : '0',
113 },
114 el(a.tag||'h2', { className:'bkte-text', style: {
115 margin:0,
116 }},
117 a.prefix && el('span', { className:'bkte-prefix', style:{color:a.prefixColor} }, a.prefix),
118 el('span', { className:'bkte-typed', style:{color:a.typedColor} }),
119 el('span', { className:'bkte-cursor', style:{color:a.cursorColor} }, a.cursorChar||'|'),
120 a.suffix && el('span', { className:'bkte-suffix', style:{color:a.prefixColor} }, a.suffix),
121 ),
122 );
123 }
124 });
125 }() );
126