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

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

157 lines 9.4 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 useState = wp.element.useState;
5 var __ = wp.i18n.__;
6 var registerBlockType = wp.blocks.registerBlockType;
7 var InspectorControls = wp.blockEditor.InspectorControls;
8 var useBlockProps = wp.blockEditor.useBlockProps;
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 var ColorPicker = wp.components.ColorPicker;
15 var Popover = wp.components.Popover;
16 var Notice = wp.components.Notice;
17
18 function renderColorControl(key, label, value, onChange, openKey, setOpenKey) {
19 var isOpen = openKey === key;
20 return el('div', { key: key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 0', gap: '8px' } },
21 el('span', { style: { fontSize: '12px', color: '#1e1e1e', flex: 1 } }, label),
22 el('div', { style: { position: 'relative', flexShrink: 0 } },
23 el('button', { type: 'button', title: value || 'none', onClick: function () { setOpenKey(isOpen ? null : key); }, style: { width: '28px', height: '28px', borderRadius: '4px', border: isOpen ? '2px solid #007cba' : '2px solid #ddd', cursor: 'pointer', padding: 0, background: value || 'transparent' } }),
24 isOpen && el(Popover, { position: 'bottom left', onClose: function () { setOpenKey(null); } },
25 el('div', { style: { padding: '8px' } }, el(ColorPicker, { color: value, enableAlpha: true, onChange: onChange }))
26 )
27 )
28 );
29 }
30
31 registerBlockType('blockenberg/lottie', {
32 title: __('Lottie Animation', 'blockenberg'),
33 icon: 'format-video',
34 category: 'bkbg-media',
35 description: __('Play a Lottie JSON animation with flexible trigger modes.', 'blockenberg'),
36
37 edit: function (props) {
38 var a = props.attributes;
39 var setAttributes = props.setAttributes;
40
41 var openColorState = useState(null);
42 var openColorKey = openColorState[0];
43 var setOpenColorKey = openColorState[1];
44
45 function sa(obj) { setAttributes(obj); }
46
47 var blockProps = useBlockProps({ className: 'bkbg-lt-outer bkbg-lt-align-' + a.align });
48
49 var wrapStyle = {
50 width : a.autoWidth ? '100%' : (a.width + 'px'),
51 height : a.autoHeight ? 'auto' : (a.height + 'px'),
52 background : a.bgColor || 'transparent',
53 borderRadius : a.borderRadius + 'px',
54 padding : a.padding + 'px',
55 boxSizing : 'border-box'
56 };
57
58 var inspector = el(InspectorControls, {},
59 el(PanelBody, { title: __('Animation Source', 'blockenberg'), initialOpen: true },
60 el(TextControl, {
61 label: __('Lottie JSON URL', 'blockenberg'),
62 value: a.lottieUrl,
63 onChange: function (v) { sa({ lottieUrl: v }); },
64 placeholder: 'https://assets…/animation.json',
65 help: __('Enter the URL of a Lottie JSON file (e.g. from LottieFiles.com).', 'blockenberg')
66 })
67 ),
68
69 el(PanelBody, { title: __('Playback', 'blockenberg'), initialOpen: false },
70 el(SelectControl, {
71 label: __('Play Trigger', 'blockenberg'), value: a.playTrigger,
72 options: [
73 { label: __('Autoplay', 'blockenberg'), value: 'autoplay' },
74 { label: __('On Hover', 'blockenberg'), value: 'hover' },
75 { label: __('On Click', 'blockenberg'), value: 'click' },
76 { label: __('On Scroll into View', 'blockenberg'), value: 'scroll' }
77 ],
78 onChange: function (v) { sa({ playTrigger: v }); }
79 }),
80 el(ToggleControl, { label: __('Loop', 'blockenberg'), checked: a.loop, onChange: function (v) { sa({ loop: v }); } }),
81 el(RangeControl, { label: __('Speed', 'blockenberg'), value: a.speed, min: 0.1, max: 4, step: 0.1, onChange: function (v) { sa({ speed: v }); } }),
82 el(SelectControl, {
83 label: __('Direction', 'blockenberg'), value: a.direction,
84 options: [{ label: __('Forward', 'blockenberg'), value: '1' }, { label: __('Reverse', 'blockenberg'), value: '-1' }],
85 onChange: function (v) { sa({ direction: v }); }
86 }),
87 !a.loop && el(ToggleControl, { label: __('Freeze on Last Frame', 'blockenberg'), checked: a.keepLastFrame, onChange: function (v) { sa({ keepLastFrame: v }); } })
88 ),
89
90 el(PanelBody, { title: __('Size & Layout', 'blockenberg'), initialOpen: false },
91 el(ToggleControl, { label: __('Full container width', 'blockenberg'), checked: a.autoWidth, onChange: function (v) { sa({ autoWidth: v }); } }),
92 !a.autoWidth && el(RangeControl, { label: __('Width (px)', 'blockenberg'), value: a.width, min: 80, max: 1200, onChange: function (v) { sa({ width: v }); } }),
93 el(ToggleControl, { label: __('Auto height (preserve ratio)', 'blockenberg'), checked: a.autoHeight, onChange: function (v) { sa({ autoHeight: v }); } }),
94 !a.autoHeight && el(RangeControl, { label: __('Height (px)', 'blockenberg'), value: a.height, min: 80, max: 1000, onChange: function (v) { sa({ height: v }); } }),
95 !a.autoWidth && el(SelectControl, {
96 label: __('Alignment', 'blockenberg'), value: a.align,
97 options: [{ label: __('Left', 'blockenberg'), value: 'left' }, { label: __('Center', 'blockenberg'), value: 'center' }, { label: __('Right', 'blockenberg'), value: 'right' }],
98 onChange: function (v) { sa({ align: v }); }
99 }),
100 el(RangeControl, { label: __('Border Radius (px)', 'blockenberg'), value: a.borderRadius, min: 0, max: 60, onChange: function (v) { sa({ borderRadius: v }); } }),
101 el(RangeControl, { label: __('Padding (px)', 'blockenberg'), value: a.padding, min: 0, max: 80, onChange: function (v) { sa({ padding: v }); } }),
102 renderColorControl('bgColor', __('Background Color', 'blockenberg'), a.bgColor, function (v) { sa({ bgColor: v }); }, openColorKey, setOpenColorKey)
103 )
104 );
105
106 /* ── Editor preview: can't run Lottie in editor, show placeholder ── */
107 return el(Fragment, {},
108 inspector,
109 el('div', blockProps,
110 el('div', { className: 'bkbg-lt-wrap', style: wrapStyle },
111 a.lottieUrl
112 ? el('div', { className: 'bkbg-lt-editor-preview' },
113 el('span', { className: 'dashicons dashicons-format-video', style: { fontSize: '48px', color: '#6b7280', display: 'block' } }),
114 el('p', { style: { fontSize: '12px', color: '#6b7280', margin: '8px 0 0' } }, __('Lottie animation will play on the front end.', 'blockenberg')),
115 el('p', { style: { fontSize: '11px', color: '#9ca3af', margin: '2px 0 0', wordBreak: 'break-all' } }, a.lottieUrl)
116 )
117 : el('div', { className: 'bkbg-lt-editor-preview bkbg-lt-empty' },
118 el('span', { className: 'dashicons dashicons-format-video', style: { fontSize: '48px', color: '#d1d5db', display: 'block' } }),
119 el('p', { style: { fontSize: '13px', color: '#9ca3af', margin: '8px 0 0' } }, __('Paste a Lottie JSON URL in the panel →', 'blockenberg'))
120 )
121 )
122 )
123 );
124 },
125
126 save: function (props) {
127 var a = props.attributes;
128
129 var saveProps = wp.blockEditor.useBlockProps.save({
130 className : 'bkbg-lt-outer bkbg-lt-align-' + a.align,
131 'data-src' : a.lottieUrl,
132 'data-trigger' : a.playTrigger,
133 'data-loop' : a.loop ? '1' : '0',
134 'data-speed' : a.speed,
135 'data-direction' : a.direction,
136 'data-keep-frame' : a.keepLastFrame ? '1' : '0'
137 });
138
139 return el('div', saveProps,
140 el('div', {
141 className: 'bkbg-lt-wrap',
142 style: {
143 width : a.autoWidth ? '100%' : (a.width + 'px'),
144 height : a.autoHeight ? 'auto' : (a.height + 'px'),
145 background : a.bgColor || undefined,
146 borderRadius : a.borderRadius ? (a.borderRadius + 'px') : undefined,
147 padding : a.padding ? (a.padding + 'px') : undefined,
148 boxSizing : 'border-box'
149 }
150 },
151 el('div', { className: 'bkbg-lt-player' })
152 )
153 );
154 }
155 });
156 }() );
157