File tree Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ export default function Edit() {
100
100
] ) ;
101
101
const initialValue = blocksToPlateNew ( content ) ;
102
102
103
+ const editorCallbacks = {
104
+ openSideBar : ( id : string ) => {
105
+ console . log ( 'editorCallbacks.openSideBar called with id:' , id ) ;
106
+ } ,
107
+ } ;
108
+
103
109
return (
104
110
< InitAtoms atomValues = { [ [ formAtom , content ] ] } >
105
111
< main className = "mx-4 mt-8 flex h-screen flex-1 flex-col" >
@@ -209,6 +215,7 @@ export default function Edit() {
209
215
field . handleChange ( newValue ) ;
210
216
} }
211
217
emblaApi = { emblaApi2 }
218
+ editorCallbacks = { editorCallbacks }
212
219
/>
213
220
</ div >
214
221
< div className = "mt-4 w-[900px]" >
Original file line number Diff line number Diff line change
1
+ export const getSevenBlockIdFromHandler = ( api : any ) : string =>
2
+ // Find the first node above the current node which has an id which is an uuid.
3
+ // Unfortunately, the sub-nodes in the tree can also have ids, which are not
4
+ // Seven ids, so we need to filter them out.k
5
+ api . above ( {
6
+ match : ( node : any ) =>
7
+ node . id ?. match (
8
+ / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / ,
9
+ ) ,
10
+ } ) [ 0 ] ?. id ;
Original file line number Diff line number Diff line change @@ -13,10 +13,14 @@ import { useSetAtom } from 'jotai';
13
13
export function PlateEditor ( props : {
14
14
value ?: Value ;
15
15
onChange ?: ( value : Value ) => void ;
16
+ editorCallbacks ?: Record < string , any > ;
16
17
} ) {
17
- const editor = useCreateEditor ( { value : props . value } ) ;
18
+ const editor = useCreateEditor ( {
19
+ value : props . value ,
20
+ } ) ;
18
21
const setEditorState = useSetAtom ( editorAtom ) ;
19
22
editor . emblaApi = props . emblaApi ;
23
+ editor . editorCallbacks = props . editorCallbacks ;
20
24
21
25
return (
22
26
< >
Original file line number Diff line number Diff line change @@ -99,19 +99,22 @@ import { TableRowElement } from '@/components/plate-ui/table-row-element';
99
99
import { TocElement } from '@/components/plate-ui/toc-element' ;
100
100
import { ToggleElement } from '@/components/plate-ui/toggle-element' ;
101
101
import UnknownElement from '@/components/plate-ui/unknown-element' ;
102
+ import { getSevenBlockIdFromHandler } from '@/components/editor/get-seven-block-id-from-handler' ;
102
103
103
104
const TitlePlugin = createPlatePlugin ( {
104
105
key : 'title' ,
105
106
node : {
106
107
isElement : true ,
107
108
type : 'title' ,
108
109
} ,
109
- // handlers: {
110
- // onKeyDown: ({ editor }) => {
111
- // // Prevent default behavior for title
112
- // console.log('TitlePlugin: onKeyDown');
113
- // },
114
- // },
110
+ handlers : {
111
+ onClick : ( { editor, api } ) => {
112
+ editor . editorCallbacks ?. openSideBar ?.( getSevenBlockIdFromHandler ( api ) ) ;
113
+ } ,
114
+ onKeyDown : ( { editor, api } ) => {
115
+ editor . editorCallbacks ?. openSideBar ?.( getSevenBlockIdFromHandler ( api ) ) ;
116
+ } ,
117
+ } ,
115
118
} ) ;
116
119
117
120
const UnknownElementPlugin = createPlatePlugin ( {
You can’t perform that action at this time.
0 commit comments