PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / blocks / src / field-art / index.js

index.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at form-builder/blocks/src/field-art/index.js

59 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Custom field icons + inserter hover previews via registerBlockType filter.
3 * Preview short-circuits edit before BaseFieldEdit (no ID allocation REST).
4 * Must load before blocks register.
5 */
6 import { addFilter } from '@wordpress/hooks';
7 import { useBlockProps } from '@wordpress/block-editor';
8 import { FIELD_ICONS } from './icons';
9 import { FIELD_PREVIEWS } from './previews';
10
11 // Example-only marker; never serialized on real blocks.
12 const PREVIEW_ATTR = '__wppbPreview';
13
14 const FieldPreview = ( { name } ) => {
15 // Inline geometry: inserter iframe styles load late and would reflow.
16 const blockProps = useBlockProps( {
17 className: 'wppb-fb-field-art-preview',
18 style: { width: '224px', maxWidth: 'none', margin: '6px auto', padding: 0, color: '#1e1e1e' },
19 } );
20 return <div { ...blockProps }>{ FIELD_PREVIEWS[ name ] || null }</div>;
21 };
22
23 addFilter(
24 'blocks.registerBlockType',
25 'profile-builder/field-art',
26 ( settings, name ) => {
27 if ( typeof name !== 'string' || ! name.startsWith( 'profile-builder/' ) ) {
28 return settings;
29 }
30
31 let next = settings;
32
33 if ( FIELD_ICONS[ name ] ) {
34 next = { ...next, icon: FIELD_ICONS[ name ] };
35 }
36
37 if ( FIELD_PREVIEWS[ name ] ) {
38 const OriginalEdit = next.edit;
39 next = {
40 ...next,
41 attributes: {
42 ...( next.attributes || {} ),
43 [ PREVIEW_ATTR ]: { type: 'boolean', default: false },
44 },
45 example: {
46 attributes: { [ PREVIEW_ATTR ]: true },
47 viewportWidth: 248,
48 },
49 edit: ( props ) =>
50 props?.attributes?.[ PREVIEW_ATTR ]
51 ? <FieldPreview name={ name } />
52 : <OriginalEdit { ...props } />,
53 };
54 }
55
56 return next;
57 }
58 );
59