import { writable } from "svelte/store";
export interface EditorState {
content: string;
language: string;
theme: string;
}
const DEFAULT_CONTENT = `
`;
function createEditorStore() {
const { subscribe, set, update } = writable({
content: DEFAULT_CONTENT,
language: "html",
theme: "vs-dark",
});
return {
subscribe,
setContent: (content: string) => update((state) => ({ ...state, content })),
setLanguage: (language: string) =>
update((state) => ({ ...state, language })),
setTheme: (theme: string) => update((state) => ({ ...state, theme })),
reset: () =>
set({
content: DEFAULT_CONTENT,
language: "html",
theme: "vs-dark",
}),
};
}
export const editorStore = createEditorStore();