-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
184 additions
and
13 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
demos/src/Tutorials/1-3-yjs_lexical/Lexical-React/Note.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import './styles.css' | ||
|
||
import { TiptapCollabProvider } from '@hocuspocus/provider' | ||
import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin' | ||
import { InitialConfigType, LexicalComposer } from '@lexical/react/LexicalComposer' | ||
import { ContentEditable } from '@lexical/react/LexicalContentEditable' | ||
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary' | ||
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin' | ||
import React from 'react' | ||
import * as Y from 'yjs' | ||
|
||
import { TNote } from './types' | ||
|
||
export default ({ note }: { note: TNote }) => { | ||
const initialConfig: InitialConfigType = { | ||
onError(error: Error): void { | ||
throw error | ||
}, | ||
namespace: 'myeditor', | ||
editable: true, | ||
} | ||
|
||
return ( | ||
<LexicalComposer initialConfig={initialConfig}> | ||
<RichTextPlugin | ||
contentEditable={<ContentEditable/>} | ||
placeholder={<p>{note.defaultContent}</p>} | ||
ErrorBoundary={LexicalErrorBoundary} | ||
/> | ||
<CollaborationPlugin | ||
id={note.id} | ||
key={note.id} | ||
// @ts-ignore | ||
providerFactory={(id, yjsDocMap) => { | ||
const doc = new Y.Doc() | ||
|
||
yjsDocMap.set(id, doc) | ||
|
||
const provider = new TiptapCollabProvider({ | ||
name: note.id, // any identifier - all connections sharing the same identifier will be synced | ||
appId: '7j9y6m10', // replace with YOUR_APP_ID | ||
token: 'notoken', // replace with your JWT | ||
document: doc, | ||
}) | ||
|
||
return provider | ||
}} | ||
shouldBootstrap={true} | ||
/> | ||
</LexicalComposer> | ||
) | ||
} |
Empty file.
26 changes: 26 additions & 0 deletions
26
demos/src/Tutorials/1-3-yjs_lexical/Lexical-React/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import './styles.css' | ||
|
||
import React from 'react' | ||
|
||
import Note from './Note' | ||
import { TNote } from './types' | ||
|
||
const notes: TNote[] = [ | ||
{ | ||
id: 'note-1', | ||
defaultContent: 'some random note text', | ||
}, | ||
{ | ||
id: 'note-2', | ||
defaultContent: 'some really random note text', | ||
}, | ||
] | ||
|
||
export default () => { | ||
|
||
return ( | ||
<div> | ||
{notes.map(note => <Note note={note} key={note.id}/>)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "tailwindcss/base"; | ||
@import "tailwindcss/components"; | ||
@import "tailwindcss/utilities"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type TNote = { | ||
id: string; | ||
defaultContent: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
tableOfContents: true | ||
--- | ||
|
||
# Introduction | ||
# Tutorials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters