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

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

210 lines 15.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 __ = wp.i18n.__;
4 var registerBlockType = wp.blocks.registerBlockType;
5 var InspectorControls = wp.blockEditor.InspectorControls;
6 var useBlockProps = wp.blockEditor.useBlockProps;
7 var RichText = wp.blockEditor.RichText;
8 var PanelColorSettings = wp.blockEditor.PanelColorSettings;
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 Button = wp.components.Button;
15
16 var _fckTC, _fckTV;
17 function _tc() { return _fckTC || (_fckTC = window.bkbgTypographyControl); }
18 function _tv(t, p) { return (_fckTV || (_fckTV = window.bkbgTypoCssVars)) ? _fckTV(t, p) : {}; }
19
20 var VERDICTS = [
21 { value: 'true', label: '�
22 True', icon: '�
23 ', color: '#15803d', bg: '#f0fdf4', border: '#86efac' },
24 { value: 'mostly-true', label: '🟢 Mostly True', icon: '🟢', color: '#166534', bg: '#dcfce7', border: '#4ade80' },
25 { value: 'mixed', label: '🟡 Mixed', icon: '🟡', color: '#92400e', bg: '#fffbeb', border: '#fcd34d' },
26 { value: 'mostly-false', label: '🟠 Mostly False', icon: '🟠', color: '#9a3412', bg: '#fff7ed', border: '#fdba74' },
27 { value: 'false', label: '❌ False', icon: '', color: '#991b1b', bg: '#fef2f2', border: '#fca5a5' },
28 { value: 'unverified', label: '❓ Unverified', icon: '', color: '#1e3a5f', bg: '#eff6ff', border: '#93c5fd' },
29 { value: 'misleading', label: '⚠️ Misleading', icon: '⚠️', color: '#713f12', bg: '#fefce8', border: '#fde047' },
30 { value: 'satire', label: '🎭 Satire', icon: '🎭', color: '#4c1d95', bg: '#f5f3ff', border: '#c4b5fd' }
31 ];
32
33 var RATING_SCALE = ['true', 'mostly-true', 'mixed', 'mostly-false', 'false'];
34
35 function getVerdict(val) {
36 return VERDICTS.find(function (v) { return v.value === val; }) || VERDICTS[3];
37 }
38
39 registerBlockType('blockenberg/fact-check', {
40 edit: function (props) {
41 var attr = props.attributes;
42 var set = props.setAttributes;
43 var verdict = getVerdict(attr.verdict);
44
45 var blockProps = useBlockProps({ className: 'bkbg-fck-outer', style: Object.assign(
46 { padding: attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px' },
47 _tv(attr.typoClaim || {}, '--bkbg-fck-cl-'),
48 _tv(attr.typoExplanation || {}, '--bkbg-fck-ex-')
49 ) });
50
51 function updateSource(idx, key, val) {
52 var arr = (attr.sources || []).map(function (s, i) {
53 if (i !== idx) return s;
54 var c = Object.assign({}, s); c[key] = val; return c;
55 });
56 set({ sources: arr });
57 }
58
59 var wrapStyle = {
60 background: attr.bgColor,
61 border: '1px solid ' + attr.borderColor,
62 borderRadius: attr.borderRadius + 'px',
63 overflow: 'hidden',
64 boxShadow: '0 1px 6px rgba(0,0,0,.06)'
65 };
66
67 /* Verdict banner */
68 var verdictBanner = el('div', { style: { background: verdict.bg, borderBottom: '1px solid ' + verdict.border, padding: '16px 20px', display: 'flex', alignItems: 'center', gap: '14px' } },
69 el('span', { style: { fontSize: '32px', lineHeight: 1, flexShrink: 0 } }, verdict.icon),
70 el('div', {},
71 el('div', { style: { fontSize: '11px', fontWeight: 600, color: attr.labelColor, textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '2px' } }, __('Verdict', 'blockenberg')),
72 el('div', { style: { fontSize: '20px', fontWeight: 800, color: verdict.color } }, verdict.label.replace(/^[^\s]+\s/, ''))
73 )
74 );
75
76 /* Rating scale */
77 var ratingScale = attr.showRatingScale && el('div', { style: { display: 'flex', gap: '4px', padding: '12px 20px', background: '#f8fafc', borderBottom: '1px solid ' + attr.borderColor } },
78 RATING_SCALE.map(function (v) {
79 var vd = getVerdict(v);
80 var isActive = attr.verdict === v || (attr.verdict === 'misleading' && v === 'mostly-false') || (attr.verdict === 'unverified' && v === 'mixed') || (attr.verdict === 'satire' && v === 'true');
81 var isExact = attr.verdict === v;
82 return el('div', { key: v, title: vd.label, style: { flex: 1, height: '8px', borderRadius: '4px', background: isExact ? vd.color : (isActive ? vd.border : '#e2e8f0'), transition: 'background .2s', cursor: 'default' } });
83 })
84 );
85
86 /* Claim */
87 var claimEl = el('div', { style: { background: attr.claimBg, borderBottom: '1px solid ' + attr.borderColor, padding: '14px 20px' } },
88 el('div', { style: { fontSize: '11px', fontWeight: 600, color: attr.labelColor, textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '6px' } }, __('Claim', 'blockenberg')),
89 el(RichText, { tagName: 'p', className: 'bkbg-fck-claim-text', value: attr.claim, allowedFormats: ['core/bold', 'core/italic'], placeholder: __('Enter the claim being fact-checked…', 'blockenberg'), style: { color: attr.claimColor, margin: 0 }, onChange: function (v) { set({ claim: v }); } })
90 );
91
92 /* Explanation */
93 var explanationEl = el('div', { style: { padding: '16px 20px', borderBottom: (attr.showSources && (attr.sources || []).length) ? '1px solid ' + attr.borderColor : 'none' } },
94 el('div', { style: { fontSize: '11px', fontWeight: 600, color: attr.labelColor, textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '8px' } }, __('Our Analysis', 'blockenberg')),
95 el(RichText, { tagName: 'div', className: 'bkbg-fck-explanation-body', value: attr.explanation, allowedFormats: ['core/bold', 'core/italic', 'core/link'], placeholder: __('Write your fact-check analysis and explanation here…', 'blockenberg'), style: { color: attr.explanationColor }, onChange: function (v) { set({ explanation: v }); } })
96 );
97
98 /* Sources */
99 var sourcesEl = attr.showSources && (attr.sources || []).length > 0 && el('div', { style: { padding: '14px 20px', background: '#fafafa' } },
100 el('div', { style: { fontSize: '11px', fontWeight: 600, color: attr.labelColor, textTransform: 'uppercase', letterSpacing: '0.06em', marginBottom: '8px' } }, __('Sources', 'blockenberg')),
101 el('ol', { style: { margin: 0, paddingLeft: '18px' } },
102 (attr.sources || []).map(function (s, i) {
103 return el('li', { key: i, style: { marginBottom: '4px', fontSize: '13px' } },
104 s.url
105 ? el('a', { href: '#', style: { color: attr.sourceLinkColor } }, s.title)
106 : el('span', { style: { color: attr.sourceTitleColor } }, s.title)
107 );
108 })
109 )
110 );
111
112 /* Reviewer */
113 var reviewerEl = attr.showReviewer && (attr.reviewerName || attr.reviewDate) && el('div', { style: { padding: '10px 20px', borderTop: '1px solid ' + attr.borderColor, background: '#f8fafc', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px', fontSize: '12px', color: attr.reviewerColor } },
114 el('span', {}, attr.reviewerName && (attr.reviewerTitle ? attr.reviewerName + ' · ' + attr.reviewerTitle : attr.reviewerName)),
115 attr.reviewDate && el('span', {}, '�
116 ' + attr.reviewDate)
117 );
118
119 var controls = el(InspectorControls, {},
120 el(PanelBody, { title: __('Verdict', 'blockenberg'), initialOpen: true },
121 el(SelectControl, {
122 label: __('Verdict', 'blockenberg'), value: attr.verdict, __nextHasNoMarginBottom: true,
123 options: VERDICTS.map(function (v) { return { label: v.label, value: v.value }; }),
124 onChange: function (v) { set({ verdict: v }); }
125 }),
126 el('div', { style: { marginTop: '8px' } },
127 el(ToggleControl, { label: __('Show Rating Scale Bar', 'blockenberg'), checked: attr.showRatingScale, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showRatingScale: v }); } })
128 )
129 ),
130 el(PanelBody, { title: __('Sources', 'blockenberg'), initialOpen: false },
131 el(ToggleControl, { label: __('Show Sources', 'blockenberg'), checked: attr.showSources, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showSources: v }); } }),
132 attr.showSources && el('div', { style: { marginTop: '10px' } },
133 (attr.sources || []).map(function (s, idx) {
134 return el('div', { key: idx, style: { marginBottom: '10px', padding: '8px', background: '#f8fafc', borderRadius: '4px', border: '1px solid #e2e8f0' } },
135 el(TextControl, { label: __('Source Title', 'blockenberg'), value: s.title, __nextHasNoMarginBottom: true, onChange: function (v) { updateSource(idx, 'title', v); } }),
136 el('div', { style: { marginTop: '4px' } },
137 el(TextControl, { label: __('URL', 'blockenberg'), value: s.url, placeholder: 'https://...', __nextHasNoMarginBottom: true, onChange: function (v) { updateSource(idx, 'url', v); } })
138 ),
139 el(Button, { variant: 'link', isDestructive: true, style: { marginTop: '4px', fontSize: '11px' }, onClick: function () { set({ sources: (attr.sources || []).filter(function (_, i) { return i !== idx; }) }); } }, __('Remove', 'blockenberg'))
140 );
141 }),
142 el(Button, { variant: 'secondary', style: { marginTop: '4px' }, onClick: function () { set({ sources: (attr.sources || []).concat([{ title: '', url: '' }]) }); } }, __('+ Add Source', 'blockenberg')),
143 el('div', { style: { marginTop: '8px' } },
144 el(ToggleControl, { label: __('Open Links in New Tab', 'blockenberg'), checked: attr.openInNewTab, __nextHasNoMarginBottom: true, onChange: function (v) { set({ openInNewTab: v }); } })
145 )
146 )
147 ),
148 el(PanelBody, { title: __('Reviewer', 'blockenberg'), initialOpen: false },
149 el(ToggleControl, { label: __('Show Reviewer', 'blockenberg'), checked: attr.showReviewer, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showReviewer: v }); } }),
150 attr.showReviewer && el('div', { style: { marginTop: '8px' } },
151 el(TextControl, { label: __('Reviewer Name', 'blockenberg'), value: attr.reviewerName, __nextHasNoMarginBottom: true, onChange: function (v) { set({ reviewerName: v }); } }),
152 el('div', { style: { marginTop: '6px' } },
153 el(TextControl, { label: __('Reviewer Title', 'blockenberg'), value: attr.reviewerTitle, __nextHasNoMarginBottom: true, onChange: function (v) { set({ reviewerTitle: v }); } })
154 ),
155 el('div', { style: { marginTop: '6px' } },
156 el(TextControl, { label: __('Review Date', 'blockenberg'), value: attr.reviewDate, placeholder: 'e.g. February 24, 2026', __nextHasNoMarginBottom: true, onChange: function (v) { set({ reviewDate: v }); } })
157 )
158 )
159 ),
160 el(PanelBody, { title: __('Style', 'blockenberg'), initialOpen: false },
161 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 20, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } }),
162 el('div', { style: { marginTop: '12px' } },
163 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 120, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
164 ),
165 el('div', { style: { marginTop: '12px' } },
166 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 120, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
167 )
168 ),
169 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
170 _tc() && el(_tc(), { label: 'Claim', typo: attr.typoClaim || {}, onChange: function (v) { set({ typoClaim: v }); } }),
171 _tc() && el(_tc(), { label: 'Analysis', typo: attr.typoExplanation || {}, onChange: function (v) { set({ typoExplanation: v }); } })
172 ),
173 el(PanelColorSettings, {
174 title: __('Colors', 'blockenberg'), initialOpen: false,
175 colorSettings: [
176 { label: __('Card Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#ffffff' }); } },
177 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#e2e8f0' }); } },
178 { label: __('Claim Background', 'blockenberg'), value: attr.claimBg, onChange: function (v) { set({ claimBg: v || '#f8fafc' }); } },
179 { label: __('Claim Text', 'blockenberg'), value: attr.claimColor, onChange: function (v) { set({ claimColor: v || '#1e293b' }); } },
180 { label: __('Label Text', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#64748b' }); } },
181 { label: __('Analysis Text', 'blockenberg'), value: attr.explanationColor, onChange: function (v) { set({ explanationColor: v || '#374151' }); } },
182 { label: __('Source Link', 'blockenberg'), value: attr.sourceLinkColor, onChange: function (v) { set({ sourceLinkColor: v || '#3b82f6' }); } },
183 { label: __('Source Title', 'blockenberg'), value: attr.sourceTitleColor, onChange: function (v) { set({ sourceTitleColor: v || '#374151' }); } },
184 { label: __('Reviewer Text', 'blockenberg'), value: attr.reviewerColor, onChange: function (v) { set({ reviewerColor: v || '#6b7280' }); } }
185 ]
186 })
187 );
188
189 return el('div', blockProps,
190 controls,
191 el('div', { style: wrapStyle },
192 verdictBanner,
193 ratingScale,
194 claimEl,
195 explanationEl,
196 sourcesEl,
197 reviewerEl
198 )
199 );
200 },
201 save: function (props) {
202 var attr = props.attributes;
203 var useBlockProps = wp.blockEditor.useBlockProps;
204 return el('div', useBlockProps.save(),
205 el('div', { className: 'bkbg-fck-app', 'data-opts': JSON.stringify(attr) })
206 );
207 }
208 });
209 }() );
210