(editor: Editor)
| 10 | const EDITABLE_TO_FOCUSED_STORE = new WeakMap<Editor, UseBoundStore<StoreApi<FocusedStore>>>() |
| 11 | |
| 12 | const 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 | |
| 33 | export const useFocused = (): [boolean, (isFocused: boolean) => void] => { |
| 34 | const editor = useEditableStatic() |
no test coverage detected