PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.11
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.11
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 / file-tree / index.js

index.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.11, at blocks/file-tree/index.js

201 lines 14.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 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 RangeControl = wp.components.RangeControl;
11 var ToggleControl = wp.components.ToggleControl;
12 var TextControl = wp.components.TextControl;
13 var SelectControl = wp.components.SelectControl;
14 var Button = wp.components.Button;
15
16 var _ftTC, _ftTV;
17 function _tc() { return (_ftTC = _ftTC || window.bkbgTypographyControl); }
18 function _tv() { return (_ftTV = _ftTV || window.bkbgTypoCssVars); }
19
20 var INDENT_OPTIONS = [
21 { label: 'Level 0 (root)', value: 0 },
22 { label: 'Level 1', value: 1 },
23 { label: 'Level 2', value: 2 },
24 { label: 'Level 3', value: 3 },
25 { label: 'Level 4', value: 4 },
26 { label: 'Level 5', value: 5 }
27 ];
28
29 function upd(arr, idx, field, val) {
30 return arr.map(function (e, i) {
31 if (i !== idx) return e;
32 var u = {}; u[field] = val;
33 return Object.assign({}, e, u);
34 });
35 }
36
37 function getExtension(name) {
38 var parts = name.split('.');
39 return parts.length > 1 ? parts[parts.length - 1].toLowerCase() : '';
40 }
41
42 function getExtColor(ext, a) {
43 if (ext === 'js' || ext === 'jsx' || ext === 'mjs') return a.jsColor;
44 if (ext === 'ts' || ext === 'tsx') return a.tsColor;
45 if (ext === 'css' || ext === 'scss' || ext === 'sass') return a.cssColor;
46 if (ext === 'html' || ext === 'htm') return a.htmlColor;
47 if (ext === 'json' || ext === 'jsonc') return a.jsonColor;
48 if (ext === 'md' || ext === 'mdx') return a.mdColor;
49 if (ext === 'py') return a.pyColor;
50 if (ext === 'png' || ext === 'jpg' || ext === 'jpeg' || ext === 'svg' || ext === 'gif' || ext === 'ico' || ext === 'webp') return a.imgColor;
51 return a.fileColor;
52 }
53
54 function getFileIcon(item, a) {
55 if (item.type === 'folder') return item.isOpen ? '📂' : '📁';
56 var ext = getExtension(item.name);
57 if (ext === 'js' || ext === 'jsx') return '';
58 if (ext === 'ts' || ext === 'tsx') return '';
59 if (ext === 'css' || ext === 'scss') return '#';
60 if (ext === 'html') return '';
61 if (ext === 'json') return '{}';
62 if (ext === 'md' || ext === 'mdx') return '';
63 if (ext === 'py') return '🐍';
64 if (ext === 'svg' || ext === 'png' || ext === 'jpg' || ext === 'ico') return '🖼';
65 return '';
66 }
67
68 function renderRow(item, idx, a, inEditor, onChange) {
69 var indent = (item.indent || 0) * 20;
70 var ext = getExtension(item.name);
71 var isFolder = item.type === 'folder';
72 var nameColor = isFolder ? a.folderColor : (a.showExtensionColors ? getExtColor(ext, a) : a.fileColor);
73
74 return el('div', {
75 key: idx,
76 className: 'bkbg-ft-row',
77 style: {
78 display: 'flex',
79 alignItems: 'center',
80 gap: '6px',
81 padding: '2px 16px 2px ' + (16 + indent) + 'px',
82 transition: 'background 0.1s',
83 background: 'transparent'
84 }
85 },
86 a.showLines && item.indent > 0 && el('span', {
87 className: 'bkbg-ft-indent-line',
88 style: {
89 display: 'inline-block',
90 width: '1px',
91 height: '1.4em',
92 background: a.lineColor,
93 opacity: 0.25,
94 flexShrink: 0,
95 marginRight: '4px'
96 }
97 }),
98 a.showIcons && el('span', {
99 className: 'bkbg-ft-icon',
100 style: { color: isFolder ? a.folderIconColor : nameColor, flexShrink: 0, fontStyle: 'normal', width: '16px', textAlign: 'center', display: 'inline-block' }
101 }, getFileIcon(item, a)),
102 el('span', { className: 'bkbg-ft-name', style: { color: nameColor, fontWeight: isFolder ? 600 : 400 } }, item.name)
103 );
104 }
105
106 registerBlockType('blockenberg/file-tree', {
107 edit: function (props) {
108 var a = props.attributes;
109 var setAttr = props.setAttributes;
110
111 return el(Fragment, null,
112 el(InspectorControls, null,
113 el(PanelBody, { title: __('Tree Settings'), initialOpen: true },
114 el(TextControl, { label: __('Title'), value: a.treeTitle, onChange: function (v) { setAttr({ treeTitle: v }); }, __nextHasNoMarginBottom: true }),
115 el(ToggleControl, { label: __('Show Title'), checked: a.showTitle, onChange: function (v) { setAttr({ showTitle: v }); }, __nextHasNoMarginBottom: true }),
116 el(ToggleControl, { label: __('Show Icons'), checked: a.showIcons, onChange: function (v) { setAttr({ showIcons: v }); }, __nextHasNoMarginBottom: true }),
117 el(ToggleControl, { label: __('Show Indent Lines'), checked: a.showLines, onChange: function (v) { setAttr({ showLines: v }); }, __nextHasNoMarginBottom: true }),
118 el(ToggleControl, { label: __('Extension Colors'), checked: a.showExtensionColors, onChange: function (v) { setAttr({ showExtensionColors: v }); }, __nextHasNoMarginBottom: true })
119 ),
120 el(PanelBody, { title: __('Files & Folders'), initialOpen: false },
121 a.files.map(function (item, i) {
122 return el('div', { key: i, style: { border: '1px solid #334155', borderRadius: 6, padding: 10, marginBottom: 8, background: '#1e293b' } },
123 el('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 } },
124 el('strong', { style: { color: '#f1f5f9', fontSize: 12 } }, (item.type === 'folder' ? '📁 ' : '📄 ') + (item.name || 'Item ' + (i + 1))),
125 el(Button, { isDestructive: true, isSmall: true, onClick: function () { setAttr({ files: a.files.filter(function (_, j) { return j !== i; }) }); } }, '')
126 ),
127 el(TextControl, { label: __('Name'), value: item.name, onChange: function (v) { setAttr({ files: upd(a.files, i, 'name', v) }); }, __nextHasNoMarginBottom: true }),
128 el(SelectControl, { label: __('Type'), value: item.type, options: [{ label: 'File', value: 'file' }, { label: 'Folder', value: 'folder' }], onChange: function (v) { setAttr({ files: upd(a.files, i, 'type', v) }); }, __nextHasNoMarginBottom: true }),
129 el(SelectControl, { label: __('Indent Level'), value: item.indent, options: INDENT_OPTIONS, onChange: function (v) { setAttr({ files: upd(a.files, i, 'indent', parseInt(v, 10)) }); }, __nextHasNoMarginBottom: true }),
130 item.type === 'folder' && el(ToggleControl, { label: __('Show as Open'), checked: item.isOpen, onChange: function (v) { setAttr({ files: upd(a.files, i, 'isOpen', v) }); }, __nextHasNoMarginBottom: true })
131 );
132 }),
133 el('div', { style: { display: 'flex', gap: 6, marginTop: 4 } },
134 el(Button, { variant: 'primary', isSmall: true, onClick: function () { setAttr({ files: a.files.concat([{ name: 'new-file.js', type: 'file', indent: 1, isOpen: false }]) }); } }, __('+ File')),
135 el(Button, { variant: 'secondary', isSmall: true, onClick: function () { setAttr({ files: a.files.concat([{ name: 'new-folder', type: 'folder', indent: 1, isOpen: true }]) }); } }, __('+ Folder'))
136 )
137 ),
138 el(PanelBody, { title: __('Typography'), initialOpen: false },
139 _tc() && el(_tc(), { label: __('Title', 'blockenberg'), value: a.typoTitle, onChange: function (v) { setAttr({ typoTitle: v }); } }),
140 _tc() && el(_tc(), { label: __('Items', 'blockenberg'), value: a.typoItem, onChange: function (v) { setAttr({ typoItem: v }); } }),
141 el(RangeControl, { label: __('Border Radius'), value: a.borderRadius, min: 0, max: 24, onChange: function (v) { setAttr({ borderRadius: v }); }, __nextHasNoMarginBottom: true })
142 ),
143 el(PanelColorSettings, {
144 title: __('Theme Colors'),
145 initialOpen: false,
146 colorSettings: [
147 { label: __('Background'), value: a.bgColor, onChange: function (v) { setAttr({ bgColor: v || '#0f172a' }); } },
148 { label: __('Header BG'), value: a.headerBg, onChange: function (v) { setAttr({ headerBg: v || '#1e293b' }); } },
149 { label: __('Border'), value: a.borderColor, onChange: function (v) { setAttr({ borderColor: v || '#1e293b' }); } },
150 { label: __('Title'), value: a.titleColor, onChange: function (v) { setAttr({ titleColor: v || '#f8fafc' }); } },
151 { label: __('Folder Name'), value: a.folderColor, onChange: function (v) { setAttr({ folderColor: v || '#60a5fa' }); } },
152 { label: __('Folder Icon'), value: a.folderIconColor, onChange: function (v) { setAttr({ folderIconColor: v || '#fbbf24' }); } },
153 { label: __('File Name'), value: a.fileColor, onChange: function (v) { setAttr({ fileColor: v || '#cbd5e1' }); } },
154 { label: __('Indent Lines'), value: a.lineColor, onChange: function (v) { setAttr({ lineColor: v || '#334155' }); } },
155 { label: __('Dot Red'), value: a.dotRed, onChange: function (v) { setAttr({ dotRed: v || '#ef4444' }); } },
156 { label: __('Dot Yellow'), value: a.dotYellow, onChange: function (v) { setAttr({ dotYellow: v || '#f59e0b' }); } },
157 { label: __('Dot Green'), value: a.dotGreen, onChange: function (v) { setAttr({ dotGreen: v || '#22c55e' }); } }
158 ]
159 }),
160 el(PanelColorSettings, {
161 title: __('File Type Colors'),
162 initialOpen: false,
163 colorSettings: [
164 { label: __('.js / .jsx'), value: a.jsColor, onChange: function (v) { setAttr({ jsColor: v || '#f59e0b' }); } },
165 { label: __('.ts / .tsx'), value: a.tsColor, onChange: function (v) { setAttr({ tsColor: v || '#3b82f6' }); } },
166 { label: __('.css / .scss'), value: a.cssColor, onChange: function (v) { setAttr({ cssColor: v || '#a78bfa' }); } },
167 { label: __('.html'), value: a.htmlColor, onChange: function (v) { setAttr({ htmlColor: v || '#f97316' }); } },
168 { label: __('.json'), value: a.jsonColor, onChange: function (v) { setAttr({ jsonColor: v || '#6ee7b7' }); } },
169 { label: __('.md / .mdx'), value: a.mdColor, onChange: function (v) { setAttr({ mdColor: v || '#94a3b8' }); } },
170 { label: __('.py'), value: a.pyColor, onChange: function (v) { setAttr({ pyColor: v || '#4ade80' }); } },
171 { label: __('Images'), value: a.imgColor, onChange: function (v) { setAttr({ imgColor: v || '#fb7185' }); } }
172 ]
173 })
174 ),
175 el('div', useBlockProps({
176 className: 'bkbg-ft-wrap',
177 style: Object.assign({ background: a.bgColor, borderRadius: a.borderRadius + 'px', border: '1px solid ' + a.borderColor, overflow: 'hidden' },
178 _tv()(a.typoTitle, '--bkbg-ft-tt-'),
179 _tv()(a.typoItem, '--bkbg-ft-ti-')
180 )
181 }),
182 el('div', { className: 'bkbg-ft-titlebar', style: { background: a.headerBg, display: 'flex', alignItems: 'center', gap: '8px', padding: '10px 16px', borderBottom: '1px solid ' + a.borderColor } },
183 el('span', { style: { width: 12, height: 12, borderRadius: '50%', background: a.dotRed, display: 'inline-block' } }),
184 el('span', { style: { width: 12, height: 12, borderRadius: '50%', background: a.dotYellow, display: 'inline-block' } }),
185 el('span', { style: { width: 12, height: 12, borderRadius: '50%', background: a.dotGreen, display: 'inline-block' } }),
186 a.showTitle && el('span', { className: 'bkbg-ft-title', style: { marginLeft: 8, color: a.titleColor } }, a.treeTitle)
187 ),
188 el('div', { className: 'bkbg-ft-body', style: { padding: '12px 0' } },
189 a.files.map(function (item, i) { return renderRow(item, i, a, true, null); })
190 )
191 )
192 );
193 },
194 save: function (props) {
195 return el('div', useBlockProps.save(),
196 el('div', { className: 'bkbg-file-tree-app', 'data-opts': JSON.stringify(props.attributes) })
197 );
198 }
199 });
200 })();
201