mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-05-18 15:26:36 +00:00
feat(store): 重构编辑器配置状态管理并添加持久化支持- 重构 useEditorConfigStore以支持完整的编辑器配置状态管理
- 添加 setConfig 方法以更新配置 - 实现配置的本地存储持久化 - 更新 EditorConfigPanel 组件以使用新的状态管理逻辑
This commit is contained in:
parent
b36c4af282
commit
96694604ec
@ -1,19 +1,21 @@
|
||||
import React from 'react';
|
||||
"use client"
|
||||
|
||||
import { useState } from 'react';
|
||||
import { useEditorConfigStore } from '@/lib/store';
|
||||
|
||||
export const EditorConfigPanel = () => {
|
||||
const { config, updateConfig } = useEditorConfigStore();
|
||||
export function EditorConfigPanel() {
|
||||
const { config, setConfig } = useEditorConfigStore();
|
||||
|
||||
const handleFontFamilyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateConfig({ fontFamily: e.target.value });
|
||||
setConfig({ fontFamily: e.target.value });
|
||||
};
|
||||
|
||||
const handleFontSizeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateConfig({ fontSize: parseInt(e.target.value) });
|
||||
setConfig({ fontSize: parseInt(e.target.value) });
|
||||
};
|
||||
|
||||
const handleLineHeightChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateConfig({ lineHeight: parseInt(e.target.value) });
|
||||
setConfig({ lineHeight: parseInt(e.target.value) });
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
|
@ -34,4 +34,29 @@ export const useEditorConfigStore = create<EditorConfigState>((set) => {
|
||||
return { config: state.defaultConfig };
|
||||
}),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
export interface EditorConfigState {
|
||||
config: any;
|
||||
setConfig: (config: any) => void;
|
||||
}
|
||||
|
||||
export const useEditorConfigStore = create<EditorConfigState>((set) => {
|
||||
// 从localStorage读取保存的配置
|
||||
let savedConfig = null;
|
||||
if (typeof window !== 'undefined') {
|
||||
savedConfig = localStorage.getItem('editorConfig');
|
||||
}
|
||||
|
||||
const parsedConfig = savedConfig ? JSON.parse(savedConfig) : {};
|
||||
|
||||
return {
|
||||
config: parsedConfig,
|
||||
setConfig: (config) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('editorConfig', JSON.stringify(config));
|
||||
}
|
||||
set({ config });
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user