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

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

194 lines 14.6 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 PanelColorSettings = wp.blockEditor.PanelColorSettings;
8 var PanelBody = wp.components.PanelBody;
9 var ToggleControl = wp.components.ToggleControl;
10 var RangeControl = wp.components.RangeControl;
11 var SelectControl = wp.components.SelectControl;
12 var TextControl = wp.components.TextControl;
13 var TextareaControl = wp.components.TextareaControl;
14 var Button = wp.components.Button;
15
16 var _tc, _tv;
17 function getTypoControl() { return _tc || (_tc = window.bkbgTypographyControl); }
18 function getTypoCssVars() { return _tv || (_tv = window.bkbgTypoCssVars); }
19
20 registerBlockType('blockenberg/sources-references', {
21 edit: function (props) {
22 var attr = props.attributes;
23 var set = props.setAttributes;
24
25 var blockProps = useBlockProps((function () {
26 var _tv = getTypoCssVars();
27 var s = { background: attr.bgColor };
28 if (_tv) {
29 Object.assign(s, _tv(attr.labelTypo, '--bksrc-lb-'));
30 Object.assign(s, _tv(attr.refTypo, '--bksrc-rf-'));
31 }
32 return { style: s };
33 })());
34
35 function updateRef(idx, key, value) {
36 var arr = attr.references.map(function (r, i) {
37 if (i !== idx) return r;
38 var copy = Object.assign({}, r);
39 copy[key] = value;
40 return copy;
41 });
42 set({ references: arr });
43 }
44
45 function RefEditor(ref, idx) {
46 return el('div', { key: idx, style: { border: '1px solid #e2e8f0', borderRadius: '6px', padding: '12px', marginBottom: '8px', background: '#f8fafc' } },
47 el('strong', { style: { fontSize: '11px', color: '#6366f1' } }, '[' + (idx + 1) + '] ' + (ref.title || 'Reference')),
48 el('div', { style: { marginTop: '8px' } },
49 el(TextControl, { label: __('Title', 'blockenberg'), value: ref.title, __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'title', v); } })
50 ),
51 el('div', { style: { marginTop: '6px' } },
52 el(TextControl, { label: __('Author(s)', 'blockenberg'), value: ref.author, __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'author', v); } })
53 ),
54 el('div', { style: { marginTop: '6px' } },
55 el(TextControl, { label: __('Publication / Source', 'blockenberg'), value: ref.publication, __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'publication', v); } })
56 ),
57 el('div', { style: { marginTop: '6px' } },
58 el(TextControl, { label: __('URL', 'blockenberg'), value: ref.url, placeholder: 'https://...', __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'url', v); } })
59 ),
60 el('div', { style: { marginTop: '6px' } },
61 el(TextControl, { label: __('Access Date', 'blockenberg'), value: ref.accessDate, placeholder: 'e.g. March 2025', __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'accessDate', v); } })
62 ),
63 el('div', { style: { marginTop: '6px' } },
64 el(TextareaControl, { label: __('Note (optional)', 'blockenberg'), value: ref.note, rows: 2, __nextHasNoMarginBottom: true, onChange: function (v) { updateRef(idx, 'note', v); } })
65 ),
66 el(Button, { variant: 'link', isDestructive: true, style: { marginTop: '6px' }, onClick: function () { set({ references: attr.references.filter(function (_, i) { return i !== idx; }) }); } }, __('Remove', 'blockenberg'))
67 );
68 }
69
70 /* Preview one reference line */
71 function RefPreview(ref, idx) {
72 var numStyle = { color: attr.numberColor, fontWeight: 700, minWidth: '28px', flexShrink: 0 };
73
74 if (attr.style === 'academic') {
75 return el('div', { key: idx, className: 'bkbg-src-item', style: { display: 'flex', gap: '8px', marginBottom: '12px', lineHeight: '1.6' } },
76 el('span', { className: 'bkbg-src-num', style: numStyle }, '[' + (idx + 1) + ']'),
77 el('div', {},
78 attr.showAuthor && ref.author && el('span', { style: { fontStyle: 'italic', color: attr.authorColor } }, ref.author + '. '),
79 el('span', { style: { color: attr.titleColor, fontWeight: 600 } }, '"' + ref.title + '."'),
80 attr.showPublication && ref.publication && el('span', { style: { color: attr.pubColor } }, ' ' + ref.publication + '.'),
81 attr.showDate && ref.accessDate && el('span', { style: { color: attr.pubColor } }, ' Accessed ' + ref.accessDate + '.'),
82 ' ',
83 attr.showUrl && ref.url && el('a', { href: '#', style: { color: attr.urlColor, wordBreak: 'break-all' } }, ref.url)
84 )
85 );
86 }
87 if (attr.style === 'cards') {
88 return el('div', { key: idx, className: 'bkbg-src-item', style: { background: attr.cardBg, border: '1px solid ' + attr.borderColor, borderRadius: attr.borderRadius + 'px', padding: '14px 16px', marginBottom: '10px', display: 'flex', gap: '12px' } },
89 el('span', { className: 'bkbg-src-num', style: Object.assign({ alignSelf: 'flex-start', marginTop: '2px' }, numStyle) }, idx + 1),
90 el('div', {},
91 el('div', { className: 'bkbg-src-card-title', style: { color: attr.titleColor } }, ref.title),
92 el('div', { className: 'bkbg-src-card-meta', style: { color: attr.authorColor, marginTop: '2px' } },
93 ref.author && el('span', {}, ref.author),
94 ref.author && ref.publication && el('span', {}, ' · '),
95 attr.showPublication && ref.publication && el('span', { style: { color: attr.pubColor } }, ref.publication),
96 attr.showDate && ref.accessDate && el('span', { style: { color: attr.pubColor } }, ' · ' + ref.accessDate)
97 ),
98 attr.showUrl && ref.url && el('a', { href: '#', className: 'bkbg-src-card-url', style: { display: 'block', marginTop: '4px', color: attr.urlColor, wordBreak: 'break-all' } }, ref.url)
99 )
100 );
101 }
102 /* minimal */
103 return el('li', { key: idx, className: 'bkbg-src-item', style: { marginBottom: '8px', color: attr.titleColor } },
104 el('strong', { className: 'bkbg-src-num', style: { color: attr.numberColor } }, (idx + 1) + '. '),
105 ref.author && attr.showAuthor && el('span', { style: { color: attr.authorColor } }, ref.author + '. '),
106 el('span', { style: { fontWeight: 600 } }, ref.title),
107 attr.showPublication && ref.publication && el('span', { style: { color: attr.pubColor } }, ', ' + ref.publication),
108 attr.showUrl && ref.url && el('span', {}, '', el('a', { href: '#', style: { color: attr.urlColor } }, ref.url))
109 );
110 }
111
112 var controls = el(InspectorControls, {},
113 el(PanelBody, { title: __('References', 'blockenberg'), initialOpen: true },
114 (attr.references || []).map(function (r, i) { return RefEditor(r, i); }),
115 el(Button, { variant: 'secondary', __nextHasNoMarginBottom: true, style: { marginTop: '8px' }, onClick: function () { set({ references: (attr.references || []).concat([{ title: 'Article Title', author: '', publication: '', url: '', accessDate: '', note: '' }]) }); } }, __('+ Add Reference', 'blockenberg'))
116 ),
117 el(PanelBody, { title: __('Style & Display', 'blockenberg'), initialOpen: false },
118 el(TextControl, { label: __('Section Label', 'blockenberg'), value: attr.label, __nextHasNoMarginBottom: true, onChange: function (v) { set({ label: v }); } }),
119 el('div', { style: { marginTop: '8px' } },
120 el(ToggleControl, { label: __('Show Label', 'blockenberg'), checked: attr.showLabel, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showLabel: v }); } })
121 ),
122 el('div', { style: { marginTop: '12px' } },
123 el(SelectControl, {
124 label: __('Style', 'blockenberg'), value: attr.style, __nextHasNoMarginBottom: true,
125 options: [{ label: 'Academic (formatted)', value: 'academic' }, { label: 'Cards', value: 'cards' }, { label: 'Minimal list', value: 'minimal' }],
126 onChange: function (v) { set({ style: v }); }
127 })
128 ),
129 el('div', { style: { marginTop: '12px' } },
130 el(ToggleControl, { label: __('Show Author', 'blockenberg'), checked: attr.showAuthor, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showAuthor: v }); } })
131 ),
132 el('div', { style: { marginTop: '4px' } },
133 el(ToggleControl, { label: __('Show Publication', 'blockenberg'), checked: attr.showPublication, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showPublication: v }); } })
134 ),
135 el('div', { style: { marginTop: '4px' } },
136 el(ToggleControl, { label: __('Show Access Date', 'blockenberg'), checked: attr.showDate, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showDate: v }); } })
137 ),
138 el('div', { style: { marginTop: '4px' } },
139 el(ToggleControl, { label: __('Show URL', 'blockenberg'), checked: attr.showUrl, __nextHasNoMarginBottom: true, onChange: function (v) { set({ showUrl: v }); } })
140 ),
141 el('div', { style: { marginTop: '4px' } },
142 el(ToggleControl, { label: __('Open Links in New Tab', 'blockenberg'), checked: attr.openInNewTab, __nextHasNoMarginBottom: true, onChange: function (v) { set({ openInNewTab: v }); } })
143 ),
144 el('div', { style: { marginTop: '12px' } },
145 el(RangeControl, { label: __('Border Radius (cards)', 'blockenberg'), value: attr.borderRadius, min: 0, max: 16, __nextHasNoMarginBottom: true, onChange: function (v) { set({ borderRadius: v }); } })
146 )
147 ),
148 el(PanelBody, { title: __('Spacing', 'blockenberg'), initialOpen: false },
149 el(RangeControl, { label: __('Padding Top', 'blockenberg'), value: attr.paddingTop, min: 0, max: 120, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingTop: v }); } }),
150 el('div', { style: { marginTop: '12px' } },
151 el(RangeControl, { label: __('Padding Bottom', 'blockenberg'), value: attr.paddingBottom, min: 0, max: 120, __nextHasNoMarginBottom: true, onChange: function (v) { set({ paddingBottom: v }); } })
152 )
153 ),
154 el(PanelBody, { title: __('Typography', 'blockenberg'), initialOpen: false },
155 getTypoControl() && el(getTypoControl(), { label: __('Label Typography'), value: attr.labelTypo || {}, onChange: function(v){ set({ labelTypo: v }); } }),
156 getTypoControl() && el(getTypoControl(), { label: __('Reference Typography'), value: attr.refTypo || {}, onChange: function(v){ set({ refTypo: v }); } })
157 ),
158 el(PanelColorSettings, {
159 title: __('Colors', 'blockenberg'), initialOpen: false,
160 colorSettings: [
161 { label: __('Background', 'blockenberg'), value: attr.bgColor, onChange: function (v) { set({ bgColor: v || '#f8fafc' }); } },
162 { label: __('Section Label', 'blockenberg'), value: attr.labelColor, onChange: function (v) { set({ labelColor: v || '#111827' }); } },
163 { label: __('Number', 'blockenberg'), value: attr.numberColor, onChange: function (v) { set({ numberColor: v || '#6366f1' }); } },
164 { label: __('Title', 'blockenberg'), value: attr.titleColor, onChange: function (v) { set({ titleColor: v || '#111827' }); } },
165 { label: __('Author', 'blockenberg'), value: attr.authorColor, onChange: function (v) { set({ authorColor: v || '#374151' }); } },
166 { label: __('Publication', 'blockenberg'), value: attr.pubColor, onChange: function (v) { set({ pubColor: v || '#6b7280' }); } },
167 { label: __('URL Link', 'blockenberg'), value: attr.urlColor, onChange: function (v) { set({ urlColor: v || '#6366f1' }); } },
168 { label: __('Border (cards)', 'blockenberg'), value: attr.borderColor, onChange: function (v) { set({ borderColor: v || '#e2e8f0' }); } },
169 { label: __('Card Background', 'blockenberg'), value: attr.cardBg, onChange: function (v) { set({ cardBg: v || '#ffffff' }); } }
170 ]
171 })
172 );
173
174 var listEl = attr.style === 'minimal' ? 'ol' : 'div';
175 return el('div', blockProps,
176 controls,
177 el('div', { style: { padding: attr.paddingTop + 'px 0 ' + attr.paddingBottom + 'px' } },
178 attr.showLabel && el('h3', { className: 'bkbg-src-label', style: { margin: '0 0 20px', color: attr.labelColor, borderBottom: '2px solid ' + attr.borderColor, paddingBottom: '10px' } }, attr.label),
179 el(listEl, { style: { margin: 0, padding: attr.style === 'minimal' ? '0 0 0 20px' : 0 } },
180 (attr.references || []).map(function (r, i) { return RefPreview(r, i); })
181 )
182 )
183 );
184 },
185 save: function (props) {
186 var attr = props.attributes;
187 var useBlockProps = wp.blockEditor.useBlockProps;
188 return el('div', useBlockProps.save(),
189 el('div', { className: 'bkbg-src-app', 'data-opts': JSON.stringify(attr) })
190 );
191 }
192 });
193 }() );
194