Skip to content

Commit

Permalink
Merge pull request #199 from KevinBatdorf/release/1.18.0
Browse files Browse the repository at this point in the history
Release 1.18.0
  • Loading branch information
KevinBatdorf authored May 29, 2023
2 parents 2c59cd6 + dffdf2f commit 02e158d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 36 deletions.
2 changes: 1 addition & 1 deletion code-block-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://code-block-pro.com/?utm_campaign=plugin&utm_source=author-uri
* Requires at least: 6.0
* Requires PHP: 7.0
* Version: 1.17.0
* Version: 1.18.0
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: code-block-pro
Expand Down
5 changes: 3 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: kbat82
Tags: block, code, syntax, snippet, highlighter, JavaScript, php, vs code
Tested up to: 6.2
Stable tag: 1.17.0
Stable tag: 1.18.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -296,12 +296,13 @@ Themes are rendered inside the editor as you type or make changes, so the code b

== Changelog ==

= 1.18.0 - 2023-05-29 =
- Feature: Adds option to output html entities
- Tweak: Creates a new button settings area to support more buttons (coming soon)
- Tweak: Changes copying class to cbp-copying
- Fix: Fixed a bug where default settings weren't saving

= 1.16.1 - 2023-05-06 =
= 1.17.0 - 2023-05-06 =
- Feature: Add line highlighting on hover
- Tweak: Updated the line highlighting sidebar language to be more clear (hopefully)
- Fix: Removed pointer events from line highlights so you can select text under it
Expand Down
25 changes: 8 additions & 17 deletions src/editor/components/ButtonsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ export const ButtonsPanel = ({
setAttributes,
}: AttributesPropsAndSetter & { bringAttentionToThemes?: boolean }) => {
const { updateThemeHistory } = useThemeStore();
const addOrRemoveButton = (button: string, value: boolean) => {
// [] attributes cause dirty posts (i guess) so this uses something like
// copy:download:etc instead of an array
const currentButtons = attributes.buttons.split(':');
const newButtons = value
? [...new Set([...currentButtons, button])]
: currentButtons.filter((b) => b !== button);
const buttons = newButtons?.filter(Boolean).join(':');

updateThemeHistory({
...attributes,
buttons,
});
setAttributes({ buttons });
};
return (
<PanelBody title={__('Buttons', 'code-block-pro')} initialOpen={false}>
<BaseControl id="code-block-pro-show-copy-button">
Expand All @@ -33,8 +18,14 @@ export const ButtonsPanel = ({
'Adds a button to copy the code',
'code-block-pro',
)}
checked={attributes.buttons?.split(':')?.includes('copy')}
onChange={(value) => addOrRemoveButton('copy', value)}
checked={attributes.copyButton}
onChange={(value) => {
setAttributes({ copyButton: value });
updateThemeHistory({
...attributes,
copyButton: value,
});
}}
/>
</BaseControl>
</PanelBody>
Expand Down
8 changes: 2 additions & 6 deletions src/editor/components/buttons/ButtonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { Attributes } from '../../../types';
import { CopyButton } from './CopyButton';

export const ButtonList = (props: Attributes) => {
const { buttons } = props;
const buttonList = buttons?.split(':') || [];
if (!buttonList.length) return null;
return buttonList.includes('copy') ? (
<CopyButton attributes={props} />
) : null;
const { copyButton } = props;
return copyButton ? <CopyButton attributes={props} /> : null;
};
10 changes: 5 additions & 5 deletions src/hooks/useDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useDefaults = ({
fontSize,
fontFamily,
lineHeight,
buttons,
copyButton,
buttonTheme,
headerType,
footerType,
Expand All @@ -32,17 +32,17 @@ export const useDefaults = ({
previousDisablePadding,
previousLineNumbers,
previousHighlightingHover,
previousButtons,
previousCopyButton,
previousButtonTheme,
} = useThemeStore();
const ready = useThemeStoreReady();
const once = useRef(false);

useEffect(() => {
if (once.current) return;
if (buttons !== undefined || previousButtons === undefined) return;
setAttributes({ buttons: previousButtons });
}, [previousButtons, setAttributes, buttons]);
if (copyButton !== undefined || !previousCopyButton) return;
setAttributes({ copyButton: previousCopyButton });
}, [previousCopyButton, copyButton, setAttributes]);

useEffect(() => {
if (once.current) return;
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ registerBlockType<Attributes>(blockConfig.name, {
renderType: { type: 'string', default: 'code' },
label: { type: 'string', default: '' },
copyButton: { type: 'boolean' },
buttons: { type: 'string' },
buttonTheme: { type: 'string' },
useDecodeURI: { type: 'boolean', default: false },
},
Expand Down
6 changes: 3 additions & 3 deletions src/state/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ThemeType = {
previousDisablePadding?: boolean;
previousLineNumbers?: boolean;
previousHighlightingHover?: boolean;
previousButtons: string;
previousCopyButton: boolean;
previousButtonTheme: string;
updateThemeHistory: (settings: Partial<Attributes>) => void;
};
Expand All @@ -37,7 +37,7 @@ const defaultSettings = {
previousDisablePadding: undefined,
previousLineNumbers: undefined,
previousHighlightingHover: undefined,
previousButtons: 'copy',
previousCopyButton: true,
previousButtonTheme: 'heroicons',
};
const storage = {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const useThemeStore = create<ThemeType>()(
previousDisablePadding: attributes.disablePadding,
previousLineNumbers: attributes.lineNumbers,
previousHighlightingHover: attributes.highlightingHover,
previousButtons: attributes.buttons,
previousCopyButton: attributes.copyButton,
previousButtonTheme: attributes.buttonTheme,
}));
},
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type Attributes = {
renderType: string;
label: string;
copyButton: boolean;
buttons: string;
buttonTheme: string;
useDecodeURI: boolean;
};
Expand Down

0 comments on commit 02e158d

Please sign in to comment.