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

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

170 lines 11.1 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
15 var TYPE_OPTIONS = [
16 { value: 'sensitive', label: 'Sensitive Content' },
17 { value: 'spoiler', label: 'Spoiler' },
18 { value: 'mature', label: 'Mature / 18+' },
19 { value: 'trauma', label: 'Trauma / Distressing' },
20 { value: 'custom', label: 'Custom' }
21 ];
22
23 var TYPE_ICONS = { sensitive: '⚠️', spoiler: '🚨', mature: '🔞', trauma: '💔', custom: '⚠️' };
24
25 var STYLE_OPTIONS = [
26 { value: 'box', label: 'Box (filled)' },
27 { value: 'banner', label: 'Banner (accent stripe)' },
28 { value: 'pill', label: 'Pill badge' },
29 { value: 'outline',label: 'Outline (no fill)' }
30 ];
31
32 function getDefaultIcon(type) { return TYPE_ICONS[type] || '⚠️'; }
33
34 var _cwTC, _cwTV;
35 function _tc() { return _cwTC || (_cwTC = window.bkbgTypographyControl); }
36 function _tv(obj, prefix) { var fn = _cwTV || (_cwTV = window.bkbgTypoCssVars); return fn ? fn(obj, prefix) : {}; }
37
38 var _IP;
39 function IP() { return _IP || (_IP = window.bkbgIconPicker); }
40
41 registerBlockType('blockenberg/content-warning', {
42 edit: function (props) {
43 var attr = props.attributes;
44 var set = props.setAttributes;
45 var blockProps = useBlockProps({ style: Object.assign({ paddingTop: attr.paddingTop + 'px', paddingBottom: attr.paddingBottom + 'px' }, _tv(attr.typoLabel, '--bkbg-cw-label-'), _tv(attr.typoMessage, '--bkbg-cw-msg-')) });
46
47 var wrapStyle = {
48 background: attr.bgColor,
49 borderRadius: attr.borderRadius + 'px',
50 overflow: 'hidden'
51 };
52 if (attr.style === 'box') {
53 wrapStyle.border = '1px solid ' + attr.borderColor;
54 wrapStyle.padding = '16px 20px';
55 } else if (attr.style === 'banner') {
56 wrapStyle.borderLeft = '5px solid ' + attr.accentColor;
57 wrapStyle.borderTop = '1px solid ' + attr.borderColor;
58 wrapStyle.borderRight = '1px solid ' + attr.borderColor;
59 wrapStyle.borderBottom = '1px solid ' + attr.borderColor;
60 wrapStyle.padding = '14px 18px';
61 } else if (attr.style === 'pill') {
62 wrapStyle.border = '2px solid ' + attr.accentColor;
63 wrapStyle.padding = '12px 18px';
64 wrapStyle.borderRadius = '999px';
65 } else if (attr.style === 'outline') {
66 wrapStyle.background = 'transparent';
67 wrapStyle.border = '2px solid ' + attr.borderColor;
68 wrapStyle.padding = '16px 20px';
69 }
70
71 var controls = el(InspectorControls, {},
72 el(PanelBody, { title: __('Warning Settings', 'blockenberg'), initialOpen: true },
73 el(SelectControl, {
74 label: __('Warning Type', 'blockenberg'), value: attr.warningType, options: TYPE_OPTIONS, __nextHasNoMarginBottom: true,
75 onChange: function (v) { set({ warningType: v, icon: getDefaultIcon(v), iconType: 'custom-char' }); }
76 }),
77 el('div', { style: { marginTop: '8px' } },
78 el(TextControl, { label: __('Label Text', 'blockenberg'), value: attr.label, __nextHasNoMarginBottom: true, onChange: function (v) { set({ label: v }); } })
79 ),
80 el('div', { style: { marginTop: '8px' } },
81 el(ToggleControl, { label: __('Show Icon', 'blockenberg'), checked: attr.showIcon, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showIcon: v }); } })
82 ),
83 attr.showIcon && el('div', { style: { marginTop: '8px' } },
84 el(IP().IconPickerControl, IP().iconPickerProps(attr, set))
85 ),
86 el('div', { style: { marginTop: '8px' } },
87 el(TextControl, { label: __('Topics (comma-separated)', 'blockenberg'), value: attr.topics, placeholder: 'violence, strong language', __nextHasNoMarginBottom: true, onChange: function (v) { set({ topics: v }); } })
88 ),
89 el('div', { style: { marginTop: '8px' } },
90 el(ToggleControl, { label: __('Show Extended Message', 'blockenberg'), checked: attr.showMessage, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showMessage: v }); } })
91 ),
92 el('div', { style: { marginTop: '8px' } },
93 el(ToggleControl, { label: __('Collapsible (hide content until confirmed)', 'blockenberg'), checked: attr.collapsible, __nextHasNoMarginBottom: true, onChange: function (v) { set({ collapsible: v }); } })
94 ),
95 attr.collapsible && el('div', { style: { marginTop: '8px' } },
96 el(TextControl, { label: __('Button Label', 'blockenberg'), value: attr.buttonLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ buttonLabel: v }); } })
97 )
98 ),
99 el(PanelBody, { title: __('Style & Spacing', 'blockenberg'), initialOpen: false },
100 el(SelectControl, { label: __('Style', 'blockenberg'), value: attr.style, options: STYLE_OPTIONS, __nextHasNoMarginBottom: true, onChange: function (v) { set({ style: v }); } }),
101 el('div', { style: { marginTop: '10px' } },
102 el(RangeControl, { label: __('Border Radius', 'blockenberg'), value: attr.borderRadius, min: 0, max: 40, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
103 ),
104 el('div', { style: { marginTop: '10px' } },
105 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } })
106 ),
107 el('div', { style: { marginTop: '10px' } },
108 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 100, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
109 )
110 ),
111 el(PanelColorSettings, {
112 title: __('Colors', 'blockenberg'), initialOpen: false,
113 colorSettings: [
114 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#fef2f2' }); } },
115 { label: __('Border', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#fca5a5' }); } },
116 { label: __('Accent', 'blockenberg'), value: attr.accentColor, onChange: function (v) { set({ accentColor: v || '#dc2626' }); } },
117 { label: __('Label Text', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#7f1d1d' }); } },
118 { label: __('Message Text', 'blockenberg'), value: attr.textColor, onChange: function (v) { set({ textColor: v || '#450a0a' }); } },
119 { label: __('Topic Tag Background', 'blockenberg'), value: attr.topicBg, onChange: function (v) { set({ topicBg: v || '#fee2e2' }); } },
120 { label: __('Topic Tag Text', 'blockenberg'), value: attr.topicColor, onChange: function (v) { set({ topicColor: v || '#991b1b' }); } },
121 { label: __('Button Background', 'blockenberg'), value: attr.btnBg, onChange: function (v) { set({ btnBg: v || '#dc2626' }); } },
122 { label: __('Button Text', 'blockenberg'), value: attr.btnColor, onChange: function (v) { set({ btnColor: v || '#ffffff' }); } }
123 ]
124 }),
125 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
126 _tc() && el(_tc(), { label: __('Label', 'blockenberg'), value: attr.typoLabel, onChange: function (v) { set({ typoLabel: v }); } }),
127 _tc() && el(_tc(), { label: __('Message', 'blockenberg'), value: attr.typoMessage, onChange: function (v) { set({ typoMessage: v }); } })
128 )
129 );
130
131 /* editor preview */
132 var topicChips = attr.topics && el('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '5px', marginTop: '8px' } },
133 attr.topics.split(',').map(function (t, i) {
134 var text = t.trim();
135 if (!text) return null;
136 return el('span', { key: i, style: { background: attr.topicBg, color: attr.topicColor, padding: '2px 10px', borderRadius: '999px', fontSize: '12px', fontWeight: 600 } }, text);
137 })
138 );
139
140 return el('div', blockProps,
141 controls,
142 el('div', { style: wrapStyle },
143 el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
144 attr.showIcon && IP().buildEditorIcon(attr.iconType, attr.icon, attr.iconDashicon, attr.iconImageUrl, { dashiconColor: attr.iconDashiconColor, style: { fontSize: '18px', lineHeight: 1 } }),
145 el('span', { className: 'bkbg-cw-label', style: { color: attr.labelColor } }, attr.label)
146 ),
147 topicChips,
148 attr.showMessage && el(RichText, {
149 tagName: 'p', className: 'bkbg-cw-message', value: attr.message,
150 allowedFormats: ['core/bold', 'core/italic', 'core/link'],
151 placeholder: __('Optional extended message…', 'blockenberg'),
152 style: { color: attr.textColor },
153 onChange: function (v) { set({ message: v }); }
154 }),
155 attr.collapsible && el('div', { style: { marginTop: '10px', textAlign: 'center' } },
156 el('span', { style: { background: attr.btnBg, color: attr.btnColor, padding: '8px 18px', borderRadius: '6px', fontSize: '13px', fontWeight: 600, display: 'inline-block', cursor: 'pointer' } }, attr.buttonLabel)
157 )
158 )
159 );
160 },
161 save: function (props) {
162 var attr = props.attributes;
163 var useBlockProps = wp.blockEditor.useBlockProps;
164 return el('div', useBlockProps.save(),
165 el('div', { className: 'bkbg-cw-app', 'data-opts': JSON.stringify(attr) })
166 );
167 }
168 });
169 }() );
170