@@ -2,6 +2,8 @@ import { ListIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react";
22import { createReactBlockSpec } from "@blocknote/react" ;
33import { useCallback , useEffect , useState } from "react" ;
44import track_event from "@/tracking" ;
5+ import AIBlockRegistry from "@/lib/ai/block_registry" ;
6+ import undent from "undent" ;
57
68interface HeadingItem {
79 id : string ;
@@ -143,25 +145,38 @@ export default createReactBlockSpec(
143145) ;
144146
145147// Component to insert this block from the editor menu
146- export const insertTableOfContents =
147- ( schema : any ) => ( editor : typeof schema . BlockNoteEditor ) => ( {
148- title : "Contents" ,
149- subtext : "Add a navigable list of all headings" ,
150- onItemClick : async ( ) => {
151- track_event ( "runbooks.block.create" , { type : "table_of_contents" } ) ;
152-
153- editor . insertBlocks (
154- [
155- {
156- type : "table_of_contents" ,
157- props : { } ,
158- } ,
159- ] ,
160- editor . getTextCursorPosition ( ) . block . id ,
161- "before" ,
162- ) ;
163- } ,
164- icon : < ListIcon size = { 18 } /> ,
165- aliases : [ "toc" , "contents" ] ,
166- group : "Content" ,
167- } ) ;
148+ export const insertTableOfContents = ( schema : any ) => ( editor : typeof schema . BlockNoteEditor ) => ( {
149+ title : "Contents" ,
150+ subtext : "Add a navigable list of all headings" ,
151+ onItemClick : async ( ) => {
152+ track_event ( "runbooks.block.create" , { type : "table_of_contents" } ) ;
153+
154+ editor . insertBlocks (
155+ [
156+ {
157+ type : "table_of_contents" ,
158+ props : { } ,
159+ } ,
160+ ] ,
161+ editor . getTextCursorPosition ( ) . block . id ,
162+ "before" ,
163+ ) ;
164+ } ,
165+ icon : < ListIcon size = { 18 } /> ,
166+ aliases : [ "toc" , "contents" ] ,
167+ group : "Content" ,
168+ } ) ;
169+
170+ AIBlockRegistry . getInstance ( ) . addBlock ( {
171+ typeName : "table_of_contents" ,
172+ friendlyName : "Table of Contents" ,
173+ shortDescription : "A navigable list of all headings" ,
174+ description : undent `
175+ Table of Contents blocks add a navigable list of all headings to the document. It takes no props.
176+
177+ Example: {
178+ "type": "table_of_contents",
179+ "props": {},
180+ }
181+ ` ,
182+ } ) ;
0 commit comments