| @@ -2,20 +2,21 @@ | ||
| 2 | 2 | import { createBlock, registerBlockType } from '@wordpress/blocks'; |
| 3 | 3 | import { addFilter } from '@wordpress/hooks'; |
| 4 | 4 | import { __ } from '@wordpress/i18n'; |
| 5 | 5 | import classnames from 'classnames'; |
| 6 | -import { Lang } from 'shiki'; | |
| 7 | 6 | import blockConfig from './block.json'; |
| 8 | 7 | import { Edit } from './editor/Edit'; |
| 9 | 8 | import { BlockFilter } from './editor/components/BlockFilter'; |
| 10 | 9 | import { FooterType } from './editor/components/FooterSelect'; |
| 11 | 10 | import { HeaderType } from './editor/components/HeaderSelect'; |
| 11 | +import { SeeMoreType } from './editor/components/SeeMoreSelect'; | |
| 12 | 12 | import { SidebarControls } from './editor/controls/Sidebar'; |
| 13 | 13 | import { ToolbarControls } from './editor/controls/Toolbar'; |
| 14 | 14 | import './editor/editor.css'; |
| 15 | 15 | import { BlockOutput } from './front/BlockOutput'; |
| 16 | +import { CopyButton } from './front/CopyButton'; | |
| 16 | 17 | import { blockIcon } from './icons'; |
| 17 | -import { Attributes } from './types'; | |
| 18 | +import { Attributes, Lang } from './types'; | |
| 18 | 19 | import { fontFamilyLong, maybeClamp } from './util/fonts'; |
| 19 | 20 | import { getMainAlias } from './util/languages'; |
| 20 | 21 | |
| 21 | 22 | registerBlockType<Attributes>(blockConfig.name, { |
| @@ -33,8 +34,9 @@ | ||
| 33 | 34 | fontSize: { type: 'string' }, |
| 34 | 35 | fontFamily: { type: 'string' }, |
| 35 | 36 | lineHeight: { type: 'string' }, |
| 36 | 37 | clampFonts: { type: 'boolean' }, |
| 38 | + editorHeight: { type: 'string' }, | |
| 37 | 39 | lineNumbers: { type: 'boolean' }, |
| 38 | 40 | headerType: { type: 'string' }, |
| 39 | 41 | headerString: { type: 'string' }, |
| 40 | 42 | disablePadding: { type: 'boolean' }, |
| @@ -41,10 +43,21 @@ | ||
| 41 | 43 | footerType: { type: 'string' }, |
| 42 | 44 | footerString: { type: 'string' }, |
| 43 | 45 | footerLink: { type: 'string' }, |
| 44 | 46 | footerLinkTarget: { type: 'boolean' }, |
| 47 | + enableMaxHeight: { type: 'boolean' }, | |
| 48 | + seeMoreType: { type: 'string' }, | |
| 49 | + seeMoreString: { type: 'string' }, | |
| 50 | + seeMoreAfterLine: { type: 'string' }, | |
| 51 | + seeMoreTransition: { type: 'boolean' }, | |
| 45 | 52 | startingLineNumber: { type: 'string' }, |
| 46 | 53 | lineNumbersWidth: { type: 'number' }, |
| 54 | + enableHighlighting: { type: 'boolean' }, | |
| 55 | + lineHighlights: { type: 'string' }, | |
| 56 | + lineHighlightColor: { type: 'string' }, | |
| 57 | + enableBlurring: { type: 'boolean' }, | |
| 58 | + lineBlurs: { type: 'string' }, | |
| 59 | + removeBlurOnHover: { type: 'boolean' }, | |
| 47 | 60 | frame: { type: 'boolean' }, |
| 48 | 61 | renderType: { type: 'string', default: 'code' }, |
| 49 | 62 | label: { type: 'string', default: '' }, |
| 50 | 63 | copyButton: { type: 'boolean' }, |
| @@ -72,8 +85,10 @@ | ||
| 72 | 85 | 'padding-bottom-disabled': |
| 73 | 86 | attributes?.footerType && |
| 74 | 87 | attributes?.footerType !== 'none', |
| 75 | 88 | 'cbp-has-line-numbers': attributes.lineNumbers, |
| 89 | + 'cbp-blur-enabled': attributes.enableBlurring, | |
| 90 | + 'cbp-unblur-on-hover': attributes.removeBlurOnHover, | |
| 76 | 91 | }), |
| 77 | 92 | style: { |
| 78 | 93 | fontSize: maybeClamp( |
| 79 | 94 | attributes.fontSize, |
| @@ -88,9 +103,16 @@ | ||
| 88 | 103 | : undefined, |
| 89 | 104 | '--cbp-line-number-width': attributes.lineNumbersWidth |
| 90 | 105 | ? `${attributes.lineNumbersWidth}px` |
| 91 | 106 | : undefined, |
| 92 | - fontFamily: fontFamilyLong(attributes.fontFamily), | |
| 107 | + '--cbp-line-highlight-color': | |
| 108 | + attributes?.enableHighlighting | |
| 109 | + ? attributes.lineHighlightColor | |
| 110 | + : undefined, | |
| 111 | + '--cbp-line-height': attributes.lineHeight, | |
| 112 | + // Disabled as ligatures will break the editor line widths | |
| 113 | + // fontFamily: fontFamilyLong(attributes.fontFamily), | |
| 114 | + fontFamily: fontFamilyLong(''), | |
| 93 | 115 | lineHeight: maybeClamp( |
| 94 | 116 | attributes.lineHeight, |
| 95 | 117 | attributes.clampFonts, |
| 96 | 118 | ), |
| @@ -96,10 +118,14 @@ | ||
| 96 | 118 | ), |
| 97 | 119 | }, |
| 98 | 120 | })}> |
| 99 | 121 | <HeaderType {...attributes} /> |
| 122 | + {attributes.copyButton && ( | |
| 123 | + <CopyButton attributes={attributes} /> | |
| 124 | + )} | |
| 100 | 125 | <Edit attributes={attributes} setAttributes={setAttributes} /> |
| 101 | 126 | <FooterType {...attributes} /> |
| 127 | + <SeeMoreType {...attributes} /> | |
| 102 | 128 | </div> |
| 103 | 129 | </> |
| 104 | 130 | ), |
| 105 | 131 | save: ({ attributes }) => <BlockOutput attributes={attributes} />, |