@@ -35,9 +35,9 @@ const NoteTextEditor = function (props: NoteEditorProps) {
3535interface NoteEditorProviderProps {
3636 inEditMode : boolean ;
3737 noteEditor : ComponentType < NoteEditorProps > ;
38- onUpdateNote : ( n : NoteData ) => void ;
39- onDeleteNote : ( n : NoteData ) => void ;
40- onCreateNote : Function ;
38+ onUpdateNote ? : ( n : NoteData ) => void ;
39+ onDeleteNote ? : ( n : NoteData ) => void ;
40+ onCreateNote ? : Function ;
4141 children ?: React . ReactNode ;
4242}
4343
@@ -50,7 +50,7 @@ function NoteEditorProvider(props: NoteEditorProviderProps) {
5050 const deleteNote = function ( ) {
5151 const val = editingNote ;
5252 setEditingNote ( null ) ;
53- return props . onDeleteNote ( val ) ;
53+ return props . onDeleteNote ?. ( val ) ;
5454 } ;
5555
5656 const onCreateNote = function ( pos ) {
@@ -76,7 +76,7 @@ function NoteEditorProvider(props: NoteEditorProviderProps) {
7676 if ( notes . includes ( n ) ) {
7777 return ;
7878 }
79- return props . onUpdateNote ( n ) ;
79+ return props . onUpdateNote ?. ( n ) ;
8080 } ;
8181
8282 //# Model editor provider gives us a nice store
@@ -257,22 +257,19 @@ function PositionEditorInner(props) {
257257 ) ;
258258}
259259
260- const NoteEditorUnderlay = function ( { padding } ) {
261- const { width } = useContext ( NoteLayoutContext ) ;
262- const { setEditingNote } = useContext ( NoteEditorContext ) as any ;
260+ function NoteEditorUnderlay ( ) {
263261 return h ( NoteRect , {
264- fill : "rgba(255,255,255,0.8)" ,
265262 style : { pointerEvents : "none" } ,
266263 className : "underlay" ,
267264 } ) ;
268- } ;
265+ }
269266
270- const NoteEditor = function ( props ) {
267+ function NoteEditor ( props ) {
271268 const { allowPositionEditing } = props ;
272- const { noteEditor } = useContext ( NoteEditorContext ) as any ;
269+ const { noteEditor, setEditingNote } = useContext ( NoteEditorContext ) as any ;
273270 const { notes, nodes, elementHeights, createNodeForNote } =
274271 useContext ( NoteLayoutContext ) ;
275- const { editedModel } = useModelEditor ( ) ;
272+ const { editedModel, model } = useModelEditor ( ) ;
276273 if ( editedModel == null ) {
277274 return null ;
278275 }
@@ -297,6 +294,8 @@ const NoteEditor = function (props) {
297294 node = newNode ;
298295 }
299296
297+ const edited = editedModel === model ;
298+
300299 return h ( ErrorBoundary , [
301300 h ( "g.note-editor.note" , [
302301 h ( NoteEditorUnderlay ) ,
@@ -305,15 +304,30 @@ const NoteEditor = function (props) {
305304 note : editedModel ,
306305 node,
307306 } ) ,
308- h ( NotePositioner , { offsetY : node . currentPos , noteHeight } , [
309- h ( noteEditor , {
310- note : editedModel ,
311- key : index ,
312- } ) ,
313- ] ) ,
307+ h (
308+ NotePositioner ,
309+ {
310+ offsetY : node . currentPos ,
311+ noteHeight,
312+ onClick ( evt ) {
313+ if ( edited ) {
314+ setEditingNote ( null ) ;
315+ evt . stopPropagation ( ) ;
316+ }
317+ } ,
318+ } ,
319+ [
320+ h ( noteEditor , {
321+ note : editedModel ,
322+ key : index ,
323+ focused : true ,
324+ edited,
325+ } ) ,
326+ ] ,
327+ ) ,
314328 ] ) ,
315329 ] ) ;
316- } ;
330+ }
317331
318332export type { NoteData } ;
319333export { NoteEditorProvider , NoteEditorContext , NoteTextEditor , NoteEditor } ;
0 commit comments