MCPcopy Index your code
hub / github.com/editablejs/editable / getStore

Function getStore

packages/editor/src/hooks/use-focused.ts:12–31  ·  view source on GitHub ↗
(editor: Editor)

Source from the content-addressed store, hash-verified

10const EDITABLE_TO_FOCUSED_STORE = new WeakMap<Editor, UseBoundStore<StoreApi<FocusedStore>>>()
11
12const getStore = (editor: Editor) => {
13 let store = EDITABLE_TO_FOCUSED_STORE.get(editor)
14 if (!store) {
15 store = create<FocusedStore>(() => ({
16 isFocused: false,
17 }))
18 EDITABLE_TO_FOCUSED_STORE.set(editor, store)
19 store.subscribe(({ isFocused }) => {
20 if (!Editable.isEditor(editor)) return
21
22 if (isFocused) {
23 editor.onFocus()
24 } else {
25 editor.onBlur()
26 }
27 })
28 }
29
30 return store
31}
32
33export const useFocused = (): [boolean, (isFocused: boolean) => void] => {
34 const editor = useEditableStatic()

Callers 2

useFocusedFunction · 0.70
use-focused.tsFile · 0.70

Calls 2

getMethod · 0.80
createFunction · 0.50

Tested by

no test coverage detected