a tool for shared writing and social publishing
1import { create } from "zustand"; 2import { Command, EditorState } from "prosemirror-state"; 3import { EditorView } from "prosemirror-view"; 4export let useEditorStates = create(() => ({ 5 lastXPosition: 0, 6 editorStates: {} as { 7 [entity: string]: 8 | { 9 editor: InstanceType<typeof EditorState>; 10 initial?: boolean; 11 view: InstanceType<typeof EditorView>; 12 keymap?: { [key: string]: Command }; 13 } 14 | undefined; 15 }, 16})); 17 18export const setEditorState = ( 19 entityID: string, 20 s: { 21 editor: InstanceType<typeof EditorState>; 22 }, 23) => { 24 useEditorStates.setState((oldState) => { 25 let existingState = oldState.editorStates[entityID]; 26 if (!existingState) return oldState; 27 return { 28 editorStates: { 29 ...oldState.editorStates, 30 [entityID]: { ...existingState, ...s }, 31 }, 32 }; 33 }); 34};