diff --git a/src/islands/note/App.tsx b/src/islands/note/App.tsx index 4948786..e75b4c7 100644 --- a/src/islands/note/App.tsx +++ b/src/islands/note/App.tsx @@ -88,17 +88,6 @@ export default (props: Props) => { }) const [getLoadError, setLoadError] = createSignal() - createEffect(() => { - if (!noteBookState.isEditMode) { - for (const note of notes.notes()) { - for (const handler of note.events?.focus ?? []) { - handler({ - isActive: false, - }) - } - } - } - }) createEffect(() => { document.title = `${noteBookMetadata.noteName} - Nanoha` }) diff --git a/src/islands/note/components/Notes.tsx b/src/islands/note/components/Notes.tsx index bf1bc90..ae78137 100644 --- a/src/islands/note/components/Notes.tsx +++ b/src/islands/note/components/Notes.tsx @@ -30,19 +30,6 @@ export default (props: { notes.notes handleUpdate() }) - createEffect(() => { - const focused = getFocusedIndex() - let i = 0 - for (const eachNote of props.notes) { - const isActive = focused === i - for (const focusEventListener of eachNote.events.focus || []) { - focusEventListener({ - isActive, - }) - } - i++ - } - }) const getNoteRect: Record DOMRect> = {} @@ -101,16 +88,9 @@ export default (props: { setFocusedIndex(index()) }} updated={handleUpdate} - on={(type, listener) => { - const thisNote = props.notes[index()] - if (!thisNote) return - if (!thisNote.events[type]) { - thisNote.events[type] = [] - } - thisNote.events[type]?.push(listener) - }} index={index()} notes={props.notes} + focusedIndex={getFocusedIndex()} /> ) diff --git a/src/islands/note/components/notes-utils.ts b/src/islands/note/components/notes-utils.ts index c56d366..84fc09c 100644 --- a/src/islands/note/components/notes-utils.ts +++ b/src/islands/note/components/notes-utils.ts @@ -35,35 +35,23 @@ export interface NoteComponentProps { setNoteData: SetStoreFunction focus(): void - on( - type: EventType, - listenter: (evt: NoteEventArgs[EventType]) => void, - ): void updated(): void index: number notes: Note[] + + focusedIndex: number } export type NoteComponent = ( props: NoteComponentProps, ) => JSX.Element -export interface NoteEvents { - focus?: ((evt: NoteEventArgs['focus']) => void)[] -} -export interface NoteEventArgs { - focus: { - isActive: boolean - } -} export interface Note { Component: NoteComponent noteData: T setNoteData: SetStoreFunction - - events: NoteEvents } export const createNotes = (): { diff --git a/src/islands/note/components/notes/ImageNote/ImageNote.tsx b/src/islands/note/components/notes/ImageNote/ImageNote.tsx index 2ca759c..fc6d885 100644 --- a/src/islands/note/components/notes/ImageNote/ImageNote.tsx +++ b/src/islands/note/components/notes/ImageNote/ImageNote.tsx @@ -10,11 +10,8 @@ import Player from './components/Player' import { ScanedImageEditor } from './components/ScanedImageEditor' export const ImageNote = ((props) => { - const [getIsActive, setIsActive] = createSignal(false) + const getIsActive = createMemo(() => props.focusedIndex === props.index) - props.on('focus', (evt) => { - setIsActive(evt.isActive) - }) const imageUrl = createMemo(() => { const nowImageBlob = props.noteData.blobs.scanedImage return nowImageBlob ? URL.createObjectURL(nowImageBlob) : null diff --git a/src/islands/note/components/notes/ImageNote/create.ts b/src/islands/note/components/notes/ImageNote/create.ts index 2b18334..dc24dc9 100644 --- a/src/islands/note/components/notes/ImageNote/create.ts +++ b/src/islands/note/components/notes/ImageNote/create.ts @@ -25,7 +25,6 @@ export const createImageNote = (initNoteData?: ImageNoteData) => { Component: ImageNote, noteData, setNoteData, - events: {}, } return addNote } diff --git a/src/islands/note/components/notes/TextNote/TextNote.tsx b/src/islands/note/components/notes/TextNote/TextNote.tsx index 43e57c6..5a394cc 100644 --- a/src/islands/note/components/notes/TextNote/TextNote.tsx +++ b/src/islands/note/components/notes/TextNote/TextNote.tsx @@ -19,10 +19,6 @@ import { ExtensionPreviewLLM, ExtensionSheet } from './tiptap/plugins' import type { TextNoteData } from './types' import './TextNoteStyle.css' -import dedent from 'dedent' -import markdownIt from 'markdown-it' -import type { SetStoreFunction } from 'solid-js/store' -import { getGoogleGenerativeAI } from '../../../../shared/gemini' import { getVisualViewport } from '../../../window-apis' import { AIDialogCore } from './AI' @@ -96,16 +92,16 @@ export const TextNote = ((props) => { props.updated() } - props.on('focus', (evt) => { - setIsActive(evt.isActive) + createEffect(() => { + setIsActive(props.focusedIndex === props.index) }) let lastActive = getIsActive() createEffect(() => { if (getIsActive() && !lastActive) { - requestAnimationFrame(() => { + setTimeout(() => { getEditor()?.commands.focus() - }) + }, 100) } lastActive = getIsActive() }) @@ -152,6 +148,7 @@ export const TextNote = ((props) => { { getEditor()?.commands.insertContent(r) + saveContent() close(null) }} initPrompt={(() => { diff --git a/src/islands/note/components/notes/TextNote/create.ts b/src/islands/note/components/notes/TextNote/create.ts index ed8781e..3602b3f 100644 --- a/src/islands/note/components/notes/TextNote/create.ts +++ b/src/islands/note/components/notes/TextNote/create.ts @@ -25,7 +25,6 @@ export const createTextNote = (initNoteData?: TextNoteData) => { Component: TextNote, noteData, setNoteData, - events: {}, } return addNote }