PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.7.0
Code Block Pro – Beautiful Syntax Highlighting v1.7.0
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 / hooks / useDefaults.ts

useDefaults.ts in Code Block Pro – Beautiful Syntax Highlighting 1.7.0, at src/hooks/useDefaults.ts

79 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect } from '@wordpress/element';
2 import { Theme } from 'shiki';
3 import { useGlobalStore } from '../state/global';
4 import { useThemeStore } from '../state/theme';
5 import { AttributesPropsAndSetter } from '../types';
6
7 export const useDefaults = ({
8 attributes,
9 setAttributes,
10 }: AttributesPropsAndSetter) => {
11 const {
12 theme,
13 fontSize,
14 fontFamily,
15 lineHeight,
16 copyButton,
17 headerType,
18 clampFonts,
19 disablePadding,
20 lineNumbers,
21 } = attributes;
22 const { previousSettings } = useGlobalStore();
23 const {
24 previousTheme,
25 previousFontSize,
26 previousFontFamily,
27 previousLineHeight,
28 previousHeaderType,
29 previousClampFonts,
30 previousDisablePadding,
31 previousLineNumbers,
32 } = useThemeStore();
33
34 useEffect(() => {
35 if (copyButton || !previousSettings.copyButton) return;
36 setAttributes({ copyButton: previousSettings.copyButton });
37 }, [previousSettings, copyButton, setAttributes]);
38
39 useEffect(() => {
40 if (theme || !previousTheme) return;
41 setAttributes({ theme: previousTheme as Theme });
42 }, [previousTheme, theme, setAttributes]);
43
44 useEffect(() => {
45 if (fontSize || !previousFontSize) return;
46 setAttributes({ fontSize: previousFontSize });
47 }, [previousFontSize, fontSize, setAttributes]);
48
49 useEffect(() => {
50 if (fontFamily || !previousFontFamily) return;
51 setAttributes({ fontFamily: previousFontFamily });
52 }, [previousFontFamily, fontFamily, setAttributes]);
53
54 useEffect(() => {
55 if (lineHeight || !previousLineHeight) return;
56 setAttributes({ lineHeight: previousLineHeight });
57 }, [previousLineHeight, lineHeight, setAttributes]);
58
59 useEffect(() => {
60 if (headerType || !previousHeaderType) return;
61 setAttributes({ headerType: previousHeaderType });
62 }, [previousHeaderType, headerType, setAttributes]);
63
64 useEffect(() => {
65 if (clampFonts || !previousClampFonts) return;
66 setAttributes({ clampFonts: previousClampFonts });
67 }, [previousClampFonts, clampFonts, setAttributes]);
68
69 useEffect(() => {
70 if (disablePadding || !previousDisablePadding) return;
71 setAttributes({ disablePadding: previousDisablePadding });
72 }, [previousDisablePadding, disablePadding, setAttributes]);
73
74 useEffect(() => {
75 if (lineNumbers || !previousLineNumbers) return;
76 setAttributes({ lineNumbers: previousLineNumbers });
77 }, [previousLineNumbers, lineNumbers, setAttributes]);
78 };
79