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

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

151 lines 9.8 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 registerBlockType = wp.blocks.registerBlockType;
5 var __ = wp.i18n.__;
6 var InspectorControls = wp.blockEditor.InspectorControls;
7 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var useBlockProps = wp.blockEditor.useBlockProps;
9 var PanelBody = wp.components.PanelBody;
10 var TextControl = wp.components.TextControl;
11 var RangeControl = wp.components.RangeControl;
12 var ToggleControl = wp.components.ToggleControl;
13
14 function getTypographyControl() { return window.bkbgTypographyControl; }
15 function getTypoCssVars() { return window.bkbgTypoCssVars; }
16
17 var COLS = ['B','I','N','G','O'];
18 var COL_RANGES = [[1,15],[16,30],[31,45],[46,60],[61,75]];
19
20 function generateCard() {
21 return COLS.map(function (col, ci) {
22 var nums = [];
23 var range = COL_RANGES[ci];
24 while (nums.length < 5) {
25 var n = Math.floor(Math.random() * (range[1] - range[0] + 1)) + range[0];
26 if (nums.indexOf(n) === -1) nums.push(n);
27 }
28 return nums;
29 });
30 }
31
32 function previewCard(a) {
33 var card = generateCard();
34 var cellSize = 52;
35
36 return el('div', { style: { background: a.sectionBg, padding: '24px', borderRadius: '14px', maxWidth: a.contentMaxWidth + 'px', fontFamily: 'system-ui,sans-serif', margin: '0 auto' } },
37 a.showTitle && el('div', { className: 'bkbg-bng-title', style: { color: a.titleColor } }, a.title),
38 a.showSubtitle && el('div', { className: 'bkbg-bng-subtitle' }, a.subtitle),
39
40 /* Caller area */
41 a.showCaller && el('div', { style: { background: a.headerBg, color: a.headerColor, borderRadius: '10px', padding: '14px', textAlign: 'center', marginBottom: '18px' } },
42 el('div', { style: { fontSize: '11px', letterSpacing: '0.1em', marginBottom: '4px', opacity: 0.7 } }, 'LAST CALLED'),
43 el('div', { style: { fontSize: '40px', fontWeight: 900, letterSpacing: '4px' } }, 'B-7'),
44 el('button', { style: { marginTop: '10px', background: a.accentColor, color: '#fff', border: 'none', borderRadius: '7px', padding: '8px 24px', fontWeight: 700, cursor: 'pointer', fontSize: '14px' } }, '▶ Call Next Number')
45 ),
46
47 /* Bingo grid */
48 el('div', { style: { border: '3px solid ' + a.headerBg, borderRadius: '10px', overflow: 'hidden' } },
49 /* Column headers */
50 el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(5,1fr)' } },
51 COLS.map(function (col) {
52 return el('div', { key: col, style: { background: a.headerBg, color: a.headerColor, textAlign: 'center', padding: '12px 0', fontWeight: 900, fontSize: '22px', letterSpacing: '2px' } }, col);
53 })
54 ),
55 /* Cells */
56 el('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(5,1fr)' } },
57 [0,1,2,3,4].map(function (row) {
58 return COLS.map(function (col, ci) {
59 var isFree = (row === 2 && ci === 2);
60 var isMarked = isFree || Math.random() < 0.3;
61 return el('div', {
62 key: col + '-' + row,
63 style: {
64 textAlign: 'center',
65 padding: '0',
66 height: cellSize + 'px',
67 lineHeight: cellSize + 'px',
68 fontWeight: isFree ? 800 : 600,
69 fontSize: isFree ? '11px' : '18px',
70 background: isFree ? a.freeColor : (isMarked ? a.markedColor : a.cellBg),
71 color: (isFree || isMarked) ? '#fff' : a.cellColor,
72 border: '1px solid ' + a.borderColor,
73 cursor: 'pointer',
74 transition: 'background 0.2s'
75 }
76 }, isFree ? 'FREE' : card[ci][row]);
77 });
78 })
79 )
80 ),
81
82 /* New card button */
83 el('div', { style: { textAlign: 'center', marginTop: '16px' } },
84 el('button', { style: { background: 'transparent', border: '2px solid ' + a.headerBg, color: a.headerBg, borderRadius: '7px', padding: '8px 20px', fontWeight: 700, cursor: 'pointer', fontSize: '14px' } }, '🔀 New Card')
85 )
86 );
87 }
88
89 registerBlockType('blockenberg/bingo-card', {
90 edit: function (props) {
91 var a = props.attributes;
92 var set = props.setAttributes;
93 var _tv = getTypoCssVars();
94 var bpStyle = {};
95 if (_tv) {
96 Object.assign(bpStyle, _tv(a.titleTypo || {}, '--bkbg-bng-title-'));
97 Object.assign(bpStyle, _tv(a.subtitleTypo || {}, '--bkbg-bng-sub-'));
98 }
99 var blockProps = useBlockProps({ className: 'bkbg-bng-root', style: bpStyle });
100
101 return el(Fragment, null,
102 el(InspectorControls, null,
103 el(PanelBody, { title: 'Content', initialOpen: true },
104 el(TextControl, { label: 'Title', value: a.title, onChange: function (v) { set({ title: v }); }, __nextHasNoMarginBottom: true }),
105 el('div', { style: { marginBottom: '16px' } }),
106 el(TextControl, { label: 'Subtitle', value: a.subtitle, onChange: function (v) { set({ subtitle: v }); }, __nextHasNoMarginBottom: true }),
107 el('div', { style: { marginBottom: '16px' } }),
108 el(ToggleControl, { label: 'Show Title', checked: a.showTitle, onChange: function (v) { set({ showTitle: v }); }, __nextHasNoMarginBottom: true }),
109 el(ToggleControl, { label: 'Show Subtitle', checked: a.showSubtitle, onChange: function (v) { set({ showSubtitle: v }); }, __nextHasNoMarginBottom: true })
110 ),
111 el(PanelBody, { title: 'Game Settings', initialOpen: false },
112 el(ToggleControl, { label: 'Show Number Caller', checked: a.showCaller, onChange: function (v) { set({ showCaller: v }); }, __nextHasNoMarginBottom: true }),
113 el(ToggleControl, { label: 'Show Called Numbers List', checked: a.showCalledList, onChange: function (v) { set({ showCalledList: v }); }, __nextHasNoMarginBottom: true }),
114 el(ToggleControl, { label: 'Auto-Call Numbers', checked: a.autoCall, onChange: function (v) { set({ autoCall: v }); }, __nextHasNoMarginBottom: true }),
115 a.autoCall && el(RangeControl, { label: 'Auto-Call Interval (seconds)', value: a.autoCallInterval, min: 2, max: 30, onChange: function (v) { set({ autoCallInterval: v }); }, __nextHasNoMarginBottom: true })
116 ),
117 el(PanelBody, { title: 'Typography', initialOpen: false },
118 (function () { var TC = getTypographyControl(); return TC ? el(TC, { label: __('Title', 'blockenberg'), value: a.titleTypo || {}, onChange: function (v) { set({ titleTypo: v }); } }) : null; })(),
119 (function () { var TC = getTypographyControl(); return TC ? el(TC, { label: __('Subtitle', 'blockenberg'), value: a.subtitleTypo || {}, onChange: function (v) { set({ subtitleTypo: v }); } }) : null; })(),
120 el(RangeControl, { label: 'Max Width (px)', value: a.contentMaxWidth, min: 300, max: 900, step: 10, onChange: function (v) { set({ contentMaxWidth: v }); }, __nextHasNoMarginBottom: true })
121 ),
122 el(PanelColorSettings, {
123 title: 'Colors',
124 initialOpen: false,
125 colorSettings: [
126 { label: 'Accent Color', value: a.accentColor, onChange: function (v) { set({ accentColor: v || '#f59e0b' }); } },
127 { label: 'Marked Cell Color', value: a.markedColor, onChange: function (v) { set({ markedColor: v || '#f59e0b' }); } },
128 { label: 'Bingo Win Color', value: a.bingoColor, onChange: function (v) { set({ bingoColor: v || '#22c55e' }); } },
129 { label: 'FREE Space Color', value: a.freeColor, onChange: function (v) { set({ freeColor: v || '#6366f1' }); } },
130 { label: 'Header Background', value: a.headerBg, onChange: function (v) { set({ headerBg: v || '#1e3a5f' }); } },
131 { label: 'Header Text', value: a.headerColor, onChange: function (v) { set({ headerColor: v || '#ffffff' }); } },
132 { label: 'Cell Background', value: a.cellBg, onChange: function (v) { set({ cellBg: v || '#ffffff' }); } },
133 { label: 'Cell Text', value: a.cellColor, onChange: function (v) { set({ cellColor: v || '#1f2937' }); } },
134 { label: 'Section Background', value: a.sectionBg, onChange: function (v) { set({ sectionBg: v || '#f8fafc' }); } },
135 { label: 'Title Color', value: a.titleColor, onChange: function (v) { set({ titleColor: v || '#1e3a5f' }); } }
136 ]
137 })
138 ),
139 el('div', blockProps, previewCard(a))
140 );
141 },
142 save: function (props) {
143 var a = props.attributes;
144 var useBlockProps = wp.blockEditor.useBlockProps;
145 return el('div', useBlockProps.save(),
146 el('div', { className: 'bkbg-bng-app', 'data-opts': JSON.stringify(a) })
147 );
148 }
149 });
150 }() );
151