| 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 { theme, fontSize, fontFamily, lineHeight, copyButton, headerType } = |
| 12 |
attributes; |
| 13 |
const { previousSettings } = useGlobalStore(); |
| 14 |
const { |
| 15 |
previousTheme, |
| 16 |
previousFontSize, |
| 17 |
previousFontFamily, |
| 18 |
previousLineHeight, |
| 19 |
previousHeaderType, |
| 20 |
} = useThemeStore(); |
| 21 |
useEffect(() => { |
| 22 |
if (copyButton || !previousSettings.copyButton) return; |
| 23 |
setAttributes({ copyButton: previousSettings.copyButton }); |
| 24 |
}, [previousSettings, copyButton, setAttributes]); |
| 25 |
|
| 26 |
useEffect(() => { |
| 27 |
if (theme || !previousTheme) return; |
| 28 |
setAttributes({ theme: previousTheme as Theme }); |
| 29 |
}, [previousTheme, theme, setAttributes]); |
| 30 |
|
| 31 |
useEffect(() => { |
| 32 |
if (fontSize || !previousFontSize) return; |
| 33 |
setAttributes({ fontSize: previousFontSize }); |
| 34 |
}, [previousFontSize, fontSize, setAttributes]); |
| 35 |
|
| 36 |
useEffect(() => { |
| 37 |
if (fontFamily || !previousFontFamily) return; |
| 38 |
setAttributes({ fontFamily: previousFontFamily }); |
| 39 |
}, [previousFontFamily, fontFamily, setAttributes]); |
| 40 |
|
| 41 |
useEffect(() => { |
| 42 |
if (lineHeight || !previousLineHeight) return; |
| 43 |
setAttributes({ lineHeight: previousLineHeight }); |
| 44 |
}, [previousLineHeight, lineHeight, setAttributes]); |
| 45 |
|
| 46 |
useEffect(() => { |
| 47 |
if (headerType || !previousHeaderType) return; |
| 48 |
setAttributes({ headerType: previousHeaderType }); |
| 49 |
}, [previousHeaderType, headerType, setAttributes]); |
| 50 |
}; |
| 51 |
|