-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetting.ts
63 lines (57 loc) · 1.66 KB
/
setting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { atomWithStore } from 'jotai-zustand';
// eslint-disable-next-line import/order
import { selectAtom } from 'jotai/utils';
import { create } from 'zustand';
import { createJSONStorage, persist } from 'zustand/middleware';
export type CsvParam = {
delim?: string;
escape?: string;
new_line?: string;
quote?: string;
};
export type SettingState = {
precision: number;
table_font_family: string;
main_font_family: string;
table_render: string;
auto_update?: boolean;
proxy?: string;
debug?: string;
csv?: CsvParam;
};
export const defaultSettings = {
precision: 4,
auto_update: true,
table_font_family: 'Consolas',
table_render: 'canvas',
main_font_family: [
'-apple-system, BlinkMacSystemFont, PingFang SC, Hiragino Sans GB',
'Segoe WPC, Segoe UI, Microsoft YaHei',
'system-ui,Ubuntu, Droid Sans,Source Han Sans SC, Source Han Sans CN, Source Han Sans',
'sans-serif',
].join(','),
csv: {},
};
export const useSettingStore = create<SettingState>()(
persist((_) => defaultSettings, {
name: 'settingStore',
storage: createJSONStorage(() => localStorage),
}),
);
export const settingAtom = atomWithStore(useSettingStore);
export const precisionAtom = selectAtom(
settingAtom,
(s) => s.precision ?? defaultSettings['precision'],
);
export const tableFontFamilyAtom = selectAtom(
settingAtom,
(s) => s.table_font_family ?? defaultSettings['table_font_family'],
);
export const mainFontFamilyAtom = selectAtom(
settingAtom,
(s) => s.main_font_family ?? defaultSettings['main_font_family'],
);
export const tableRenderAtom = selectAtom(
settingAtom,
(s) => s.table_render ?? defaultSettings['table_render'],
);