File tree Expand file tree Collapse file tree 11 files changed +204
-1
lines changed
examples/08-extensions/01-tiptap-arrow-conversion Expand file tree Collapse file tree 11 files changed +204
-1
lines changed Original file line number Diff line number Diff line change 6
6
"theming" : " Theming" ,
7
7
"interoperability" : " Interoperability" ,
8
8
"custom-schema" : " Custom Schemas" ,
9
- "collaboration" : " Collaboration"
9
+ "collaboration" : " Collaboration" ,
10
+ "extensions" : " Extensions"
10
11
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "playground" : true ,
3
+ "docs" : true ,
4
+ "author" : " komsenapati" ,
5
+ "tags" : [" Extension" ],
6
+ "pro" : true
7
+ }
Original file line number Diff line number Diff line change
1
+ import "@blocknote/core/fonts/inter.css" ;
2
+ import { useCreateBlockNote } from "@blocknote/react" ;
3
+ import { BlockNoteView } from "@blocknote/mantine" ;
4
+ import "@blocknote/mantine/style.css" ;
5
+ import { ArrowConversionExtension } from "./ArrowConversionExtension" ;
6
+
7
+ export default function App ( ) {
8
+ // Creates a new editor instance.
9
+ const editor = useCreateBlockNote ( {
10
+ _tiptapOptions : {
11
+ extensions : [ ArrowConversionExtension ]
12
+ }
13
+ } ) ;
14
+
15
+ // Renders the editor instance using a React component.
16
+ return < BlockNoteView editor = { editor } /> ;
17
+ }
Original file line number Diff line number Diff line change
1
+ import { Extension } from "@tiptap/core" ;
2
+
3
+ export const ArrowConversionExtension = Extension . create ( {
4
+ name : 'arrowConversion' ,
5
+
6
+ addInputRules ( ) {
7
+ return [
8
+ {
9
+ find : / - > / g,
10
+ handler : ( { state, range, chain } ) => {
11
+ const { from, to } = range ;
12
+ const tr = state . tr . replaceWith ( from , to , state . schema . text ( '→' ) ) ;
13
+ chain ( ) . insertContent ( tr ) . run ( ) ;
14
+ } ,
15
+ } ,
16
+ ] ;
17
+ } ,
18
+ } )
Original file line number Diff line number Diff line change
1
+ # TipTap extension (arrow InputRule)
2
+
3
+ This example shows how to set up a BlockNote editor with a TipTap extension that registers an InputRule to convert ` -> ` into ` → ` .
4
+
5
+ ** Try it out:** Type ` -> ` anywhere in the editor and see how it's automatically converted to a single arrow unicode character.
Original file line number Diff line number Diff line change
1
+ < html lang ="en ">
2
+ < head >
3
+ < script >
4
+ <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
5
+ </ script >
6
+ < meta charset ="UTF-8 " />
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
8
+ < title > TipTap extension (arrow InputRule)</ title >
9
+ </ head >
10
+ < body >
11
+ < div id ="root "> </ div >
12
+ < script type ="module " src ="./main.tsx "> </ script >
13
+ </ body >
14
+ </ html >
Original file line number Diff line number Diff line change
1
+ // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
2
+ import React from "react" ;
3
+ import { createRoot } from "react-dom/client" ;
4
+ import App from "./App" ;
5
+
6
+ const root = createRoot ( document . getElementById ( "root" ) ! ) ;
7
+ root . render (
8
+ < React . StrictMode >
9
+ < App />
10
+ </ React . StrictMode >
11
+ ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @blocknote/example-tiptap-arrow-conversion" ,
3
+ "description" : " AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY" ,
4
+ "private" : true ,
5
+ "version" : " 0.12.4" ,
6
+ "scripts" : {
7
+ "start" : " vite" ,
8
+ "dev" : " vite" ,
9
+ "build" : " tsc && vite build" ,
10
+ "preview" : " vite preview" ,
11
+ "lint" : " eslint . --max-warnings 0"
12
+ },
13
+ "dependencies" : {
14
+ "@blocknote/core" : " latest" ,
15
+ "@blocknote/react" : " latest" ,
16
+ "@blocknote/ariakit" : " latest" ,
17
+ "@blocknote/mantine" : " latest" ,
18
+ "@blocknote/shadcn" : " latest" ,
19
+ "react" : " ^18.3.1" ,
20
+ "react-dom" : " ^18.3.1"
21
+ },
22
+ "devDependencies" : {
23
+ "@types/react" : " ^18.0.25" ,
24
+ "@types/react-dom" : " ^18.0.9" ,
25
+ "@vitejs/plugin-react" : " ^4.3.1" ,
26
+ "eslint" : " ^8.10.0" ,
27
+ "vite" : " ^5.3.4"
28
+ },
29
+ "eslintConfig" : {
30
+ "extends" : [
31
+ " ../../../.eslintrc.js"
32
+ ]
33
+ },
34
+ "eslintIgnore" : [
35
+ " dist"
36
+ ]
37
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "__comment" : " AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY" ,
3
+ "compilerOptions" : {
4
+ "target" : " ESNext" ,
5
+ "useDefineForClassFields" : true ,
6
+ "lib" : [
7
+ " DOM" ,
8
+ " DOM.Iterable" ,
9
+ " ESNext"
10
+ ],
11
+ "allowJs" : false ,
12
+ "skipLibCheck" : true ,
13
+ "esModuleInterop" : false ,
14
+ "allowSyntheticDefaultImports" : true ,
15
+ "strict" : true ,
16
+ "forceConsistentCasingInFileNames" : true ,
17
+ "module" : " ESNext" ,
18
+ "moduleResolution" : " Node" ,
19
+ "resolveJsonModule" : true ,
20
+ "isolatedModules" : true ,
21
+ "noEmit" : true ,
22
+ "jsx" : " react-jsx" ,
23
+ "composite" : true
24
+ },
25
+ "include" : [
26
+ " ."
27
+ ],
28
+ "__ADD_FOR_LOCAL_DEV_references" : [
29
+ {
30
+ "path" : " ../../../packages/core/"
31
+ },
32
+ {
33
+ "path" : " ../../../packages/react/"
34
+ }
35
+ ]
36
+ }
Original file line number Diff line number Diff line change
1
+ // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
2
+ import react from "@vitejs/plugin-react" ;
3
+ import * as fs from "fs" ;
4
+ import * as path from "path" ;
5
+ import { defineConfig } from "vite" ;
6
+ // import eslintPlugin from "vite-plugin-eslint";
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig ( ( conf ) => ( {
9
+ plugins : [ react ( ) ] ,
10
+ optimizeDeps : { } ,
11
+ build : {
12
+ sourcemap : true ,
13
+ } ,
14
+ resolve : {
15
+ alias :
16
+ conf . command === "build" ||
17
+ ! fs . existsSync ( path . resolve ( __dirname , "../../packages/core/src" ) )
18
+ ? { }
19
+ : ( {
20
+ // Comment out the lines below to load a built version of blocknote
21
+ // or, keep as is to load live from sources with live reload working
22
+ "@blocknote/core" : path . resolve (
23
+ __dirname ,
24
+ "../../packages/core/src/"
25
+ ) ,
26
+ "@blocknote/react" : path . resolve (
27
+ __dirname ,
28
+ "../../packages/react/src/"
29
+ ) ,
30
+ } as any ) ,
31
+ } ,
32
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments