tiptap/demos/src/Tutorials/1-3-yjs_lexical/Lexical-React/Note.tsx
Arnau Gómez Farell 89bd9c7d29
Fix/enforce-type-imports-so-that-bundler-ignores-types (#6132)
* fix: enforce type imports so that the bundler ignores types

* chore: add changeset

* fix: export types with export type keyword
2025-03-03 15:15:30 +01:00

54 lines
1.6 KiB
TypeScript

import './styles.css'
import { TiptapCollabProvider } from '@hocuspocus/provider'
import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin'
import type { InitialConfigType } from '@lexical/react/LexicalComposer'
import { 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 type { TNote } from './types.js'
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>
)
}