Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2.0 KiB
2.0 KiB
Tiptap Editor Integration
Core Concepts
- We use Tiptap for rich text editing throughout the app
- Extensions are customized to work with React components via
renderReact - Most extensions live in
web/components/editor/
Custom Extension Pattern
// 1. Create a React component for the view
const MyComponent = (props: MyProps) => { ... }
// 2. Extend the Tiptap extension
export const DisplayMyExtension = TiptapExtension.extend({
// For SSR and copy/paste
renderHTML({ HTMLAttributes }) {
return [
'tag-name',
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
0,
]
},
// For React rendering
renderReact(attrs: any, children: ReactNode) {
return <MyComponent {...attrs}>{children}</MyComponent>
},
})
Key Features
nodeViewMiddlewarewraps extensions to handle node selection styling- Use
renderHTMLfor SSR and clipboard operations - Use
renderReactfor interactive React components - Extensions are composed in
editorExtensionsarray in editor.tsx
Best Practices
- Keep React components and Tiptap extensions co-located
- Use
mergeAttributesto handle HTML attributes properly - Use nodeViewMiddleware for consistent selection styling
Server-Side Parsing
On the server we use a simplified version that converts rich content to plain text
common/src/util/parse.ts- Main parsing logic for the servercommon/src/util/parse.native.ts- Mobile app versioncommon/src/api/zod-types.ts- api validation of tiptap json format (you don't have to change this)
Adding a New Component
-
Web (Editor):
- Create extension file in
web/components/editor/ - Add React component for interactive view
- Implement
renderHTMLandrenderReact - Add to
editorExtensionsin editor.tsx
- Create extension file in
-
Common (Server/Types):
- Add extension to parse.ts and parse.native.ts
- Add
renderTextimplementation
-
Testing (Humans only for now):
- Test first load of content isn't wonky
- Test copy/paste behavior
- Test server-side parsing doesn't crash