Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738import { create } from "zustand";import { subscribeWithSelector } from "zustand/middleware";import { Command, EditorState } from "prosemirror-state";import { EditorView } from "prosemirror-view";export let useEditorStates = create( subscribeWithSelector(() => ({ lastXPosition: 0, editorStates: {} as { [entity: string]: | { editor: InstanceType<typeof EditorState>; initial?: boolean; view: InstanceType<typeof EditorView>; keymap?: { [key: string]: Command }; } | undefined; }, })),);
export const setEditorState = ( entityID: string, s: { editor: InstanceType<typeof EditorState>; },) => { useEditorStates.setState((oldState) => { let existingState = oldState.editorStates[entityID]; if (!existingState) return oldState; return { editorStates: { ...oldState.editorStates, [entityID]: { ...existingState, ...s }, }, }; });};