PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.13.0
Code Block Pro – Beautiful Syntax Highlighting v1.13.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
← All changes | src/state/theme.ts +65 -10 1.1.01.13.0 View file →
@@ -1,28 +1,83 @@
1 -import { Theme } from 'shiki';
1 +import apiFetch from '@wordpress/api-fetch';
2 2 import create from 'zustand';
3 3 import { devtools, persist } from 'zustand/middleware';
4 +import { Attributes } from '../types';
4 5
5 6 type ThemeType = {
6 - previousTheme: Theme;
7 - setPreviousTheme: (theme: Theme) => void;
7 + previousTheme: string;
8 + previousLineHeight: string;
9 + previousFontFamily?: string;
10 + previousFontSize: string;
11 + previousHeaderType: string;
12 + previousFooterType?: string;
13 + previousClampFonts?: boolean;
14 + previousDisablePadding?: boolean;
15 + previousLineNumbers?: boolean;
16 + updateThemeHistory: (settings: Partial<Attributes>) => void;
8 17 };
18 +const path = '/wp/v2/settings';
19 +const getSettings = async (name: string) => {
20 + const allSettings = await apiFetch({ path });
21 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22 + // @ts-ignore-next-line
23 + return allSettings?.[name];
24 +};
9 25 export const useThemeStore = create<ThemeType>()(
10 26 persist(
11 27 devtools(
12 28 (set) => ({
13 29 previousTheme: 'nord',
14 - setPreviousTheme(theme: Theme) {
15 - set({ previousTheme: theme });
30 + previousLineHeight: '1.25rem',
31 + previousFontFamily: undefined,
32 + previousFontSize: '.875rem',
33 + previousHeaderType: 'headlights',
34 + previousFooterType: undefined,
35 + previousClampFonts: undefined,
36 + previousDisablePadding: undefined,
37 + previousLineNumbers: undefined,
38 + updateThemeHistory(attributes) {
39 + set((state) => ({
40 + ...state,
41 + previousTheme: attributes.theme,
42 + previousLineHeight: attributes.lineHeight,
43 + previousFontFamily: attributes.fontFamily,
44 + previousFontSize: attributes.fontSize,
45 + previousHeaderType: attributes.headerType,
46 + previousFooterType: attributes.footerType,
47 + previousClampFonts: attributes.clampFonts,
48 + previousDisablePadding: attributes.disablePadding,
49 + previousLineNumbers: attributes.lineNumbers,
50 + }));
16 51 },
17 52 }),
18 - { name: 'Code Block Pro Theme' },
53 + { name: 'Code Block Pro Theme Settings' },
19 54 ),
20 55 {
21 - name: 'code-block-pro-last-theme',
22 - getStorage: () => localStorage,
23 - partialize: (state) => ({
24 - previousTheme: state?.previousTheme ?? null,
56 + name: 'code_block_pro_settings',
57 + getStorage: () => ({
58 + getItem: async (name: string) => {
59 + const settings = await getSettings(name);
60 + return JSON.stringify({
61 + version: settings?.version ?? 0,
62 + state: settings,
63 + });
64 + },
65 + setItem: async (name: string, value: string) => {
66 + const { state, version } = JSON.parse(value);
67 + const data = {
68 + [name]: Object.assign(
69 + (await getSettings(name)) ?? {},
70 + state,
71 + version,
72 + ),
73 + };
74 + await apiFetch({ path, method: 'POST', data });
75 + },
76 + removeItem: async (name: string) => {
77 + const data = { [name]: null };
78 + return await apiFetch({ path, method: 'POST', data });
79 + },
25 80 }),
26 81 },
27 82 ),
28 83 );