PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.6
Code Block Pro – Beautiful Syntax Highlighting v1.27.6
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 / Editor.tsx

Editor.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.27.6, at src/Editor.tsx

119 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useBlockProps as blockProps } from '@wordpress/block-editor';
2 import { applyFilters } from '@wordpress/hooks';
3 import classnames from 'classnames';
4 import defaultThemes from './defaultThemes.json';
5 import { Edit } from './editor/Edit';
6 import { FooterType } from './editor/components/FooterSelect';
7 import { HeaderType } from './editor/components/HeaderSelect';
8 import { SeeMoreType } from './editor/components/SeeMoreSelect';
9 import { ButtonList } from './editor/components/buttons/ButtonList';
10 import { SidebarControls } from './editor/controls/Sidebar';
11 import { ToolbarControls } from './editor/controls/Toolbar';
12 import { AttributesPropsAndSetter } from './types';
13 import { ThemeOption } from './types';
14 import { findLineNumberColor } from './util/colors';
15 import { fontFamilyLong, maybeClamp } from './util/fonts';
16
17 export const Editor = ({
18 attributes,
19 setAttributes,
20 }: AttributesPropsAndSetter) => {
21 const {
22 clampFonts,
23 disablePadding,
24 enableBlurring,
25 enableHighlighting,
26 footerType,
27 fontSize,
28 fontFamily,
29 highestLineNumber,
30 highlightingHover,
31 lineHeight,
32 lineHighlightColor,
33 lineNumbers,
34 lineNumbersWidth,
35 removeBlurOnHover,
36 startingLineNumber,
37 tabSize,
38 theme,
39 useTabs,
40 } = attributes;
41 // To add custom styles
42 const themes = applyFilters(
43 'blocks.codeBlockPro.themes',
44 defaultThemes,
45 ) as ThemeOption;
46 const styles = themes[theme]?.styles;
47
48 return (
49 <>
50 <SidebarControls
51 attributes={attributes}
52 setAttributes={setAttributes}
53 />
54 <ToolbarControls
55 attributes={attributes}
56 setAttributes={setAttributes}
57 />
58 <div
59 {...blockProps({
60 className: classnames('code-block-pro-editor', {
61 'padding-disabled': disablePadding,
62 'padding-bottom-disabled':
63 footerType && footerType !== 'none',
64 'cbp-has-line-numbers': lineNumbers,
65 'cbp-blur-enabled': enableBlurring,
66 'cbp-unblur-on-hover': removeBlurOnHover,
67 'cbp-highlight-hover': highlightingHover,
68 }),
69 style: {
70 fontSize: maybeClamp(fontSize, clampFonts),
71 '--cbp-line-number-color': lineNumbers
72 ? findLineNumberColor(attributes)
73 : undefined,
74 '--cbp-line-number-start':
75 Number(startingLineNumber) > 1
76 ? startingLineNumber
77 : undefined,
78 '--cbp-line-number-width': highestLineNumber
79 ? `calc(${
80 String(highestLineNumber).length
81 } * ${fontSize})`
82 : lineNumbersWidth // bw compatability
83 ? `${lineNumbersWidth}px`
84 : undefined,
85 '--cbp-line-highlight-color':
86 enableHighlighting || highlightingHover
87 ? lineHighlightColor
88 : undefined,
89 '--cbp-line-height': lineHeight,
90 tabSize:
91 useTabs === undefined
92 ? undefined // bw compatability
93 : tabSize,
94 fontFamily: fontFamilyLong(fontFamily),
95 lineHeight: maybeClamp(lineHeight, clampFonts),
96 ...Object.entries(styles ?? {}).reduce(
97 (acc, [key, value]) => ({
98 ...acc,
99 [`--shiki-${key}`]: value,
100 }),
101 {},
102 ),
103 ...(applyFilters(
104 'blocks.codeBlockPro.additionalEditorAttributes',
105 {},
106 attributes,
107 ) as object),
108 },
109 })}>
110 <HeaderType {...attributes} />
111 <ButtonList {...attributes} />
112 <Edit attributes={attributes} setAttributes={setAttributes} />
113 <FooterType {...attributes} />
114 <SeeMoreType {...attributes} />
115 </div>
116 </>
117 );
118 };
119