PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.2.1
Code Block Pro – Beautiful Syntax Highlighting v1.2.1
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / index.tsx

index.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.2.1, at src/index.tsx

74 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { RichText, useBlockProps as blockProps } from '@wordpress/block-editor';
2 import { registerBlockType } from '@wordpress/blocks';
3 import { addFilter } from '@wordpress/hooks';
4 import { __ } from '@wordpress/i18n';
5 import blockConfig from './block.json';
6 import { Edit } from './editor/Edit';
7 import { BlockFilter } from './editor/components/BlockFilter';
8 import { SidebarControls } from './editor/controls/Sidebar';
9 import { ToolbarControls } from './editor/controls/Toolbar';
10 import './editor/editor.css';
11 import { CopyButton } from './front/CopyButton';
12 import './front/style.css';
13 import { blockIcon } from './icons';
14 import { Attributes } from './types';
15
16 registerBlockType<Attributes>(blockConfig.name, {
17 ...blockConfig,
18 icon: blockIcon,
19 // Types seem to be mismatched if importing these from block.json
20 attributes: {
21 code: { type: 'string' },
22 codeHTML: { type: 'string' },
23 language: { type: 'string' },
24 theme: { type: 'string' },
25 align: { type: 'string', default: 'center' },
26 bgColor: { type: 'string', default: '#282a37' },
27 textColor: { type: 'string', default: '#f8f8f2' },
28 lineNumbers: { type: 'boolean' },
29 startingLineNumber: { type: 'number', default: 1 },
30 frame: { type: 'boolean' },
31 renderType: { type: 'string', default: 'code' },
32 label: { type: 'string', default: '' },
33 copyButton: { type: 'boolean' },
34 },
35 title: __('Code Pro', 'code-block-pro'),
36 edit: ({ attributes, setAttributes }) => (
37 <>
38 <SidebarControls
39 attributes={attributes}
40 setAttributes={setAttributes}
41 />
42 <ToolbarControls
43 attributes={attributes}
44 setAttributes={setAttributes}
45 />
46 <div {...blockProps({ className: 'code-block-pro-editor' })}>
47 <Edit attributes={attributes} setAttributes={setAttributes} />
48 </div>
49 </>
50 ),
51 save: ({ attributes }) => (
52 <div {...blockProps.save()}>
53 {attributes.code?.length > 0 ? (
54 <>
55 {attributes.copyButton && (
56 <CopyButton attributes={attributes} />
57 )}
58 <RichText.Content value={attributes.codeHTML} />
59 </>
60 ) : null}
61 </div>
62 ),
63 });
64
65 addFilter(
66 'editor.BlockEdit',
67 blockConfig.name,
68 (CurrentMenuItems) =>
69 // Not sure how to type these incoming props
70 // eslint-disable-next-line
71 (props: any) =>
72 BlockFilter(CurrentMenuItems, props),
73 );
74